Created
March 1, 2018 21:14
-
-
Save mczachurski/e29b5496b4556933b0db19992c723259 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private func prepareToken(user: User) throws -> JwtTokenResponseDto { | |
let payload = [ | |
ClaimsNames.name.rawValue : user.email, | |
ClaimsNames.roles.rawValue : user.getRolesNames(), | |
ClaimsNames.issuer.rawValue : self.configuration.issuer, | |
ClaimsNames.issuedAt.rawValue : Date().timeIntervalSince1970, | |
ClaimsNames.expiration.rawValue : Date().addingTimeInterval(36000).timeIntervalSince1970 | |
] as [String : Any] | |
guard let jwt = JWTCreator(payload: payload) else { | |
throw PrepareTokenError() | |
} | |
let token = try jwt.sign(alg: .hs256, key: self.configuration.secret) | |
let tokenDto = JwtTokenResponseDto(token: token) | |
return tokenDto | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment