Refresh token

A refresh token is very similar to the access token. We do not need any user-specific information, except for the ID. The reason is that the refresh token is only used to get a new access token. The refresh token is never sent to any service except for the user service. The expiration of a refresh token is longer than an access token, so the default expiration time will be longer.

Create a RefreshToken.swift file in Sources/App/Models and insert the following content:

import Vaporimport JWTstruct RefreshToken: JWTPayload {    let id: Int    let iat: TimeInterval    let exp: TimeInterval        init(user: User, expiration: TimeInterval = 24 * 60 * 60 * 30) {        let now = Date().timeIntervalSince1970                self.id = user.id ?? 0        self.iat = now self.exp ...

Get Hands-On Swift 5 Microservices Development now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.