Skip to content

Instantly share code, notes, and snippets.

@mczachurski
Created March 1, 2018 21:14
Show Gist options
  • Save mczachurski/e29b5496b4556933b0db19992c723259 to your computer and use it in GitHub Desktop.
Save mczachurski/e29b5496b4556933b0db19992c723259 to your computer and use it in GitHub Desktop.
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