Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.63 KB | None | 0 0
  1. fun createJwt(userId: UUID): Either<TokenCreationException, String> =
  2.     Either.fx<TokenCreationException, String> {
  3.         val audience = audience.mapLeft { TokenCreationException(it) }.bind()
  4.         val algorithmSecret = algorithmSecret.mapLeft { TokenCreationException(it) }.bind()
  5.         val algorithm = algorithm(algorithmSecret)
  6.             .mapLeft { TokenCreationException(it) }.bind()
  7.  
  8.         JWT.create()
  9.             .withAudience(audience)
  10.             .withIssuer(userId.toString())
  11.             .withExpiresAt(OffsetDateTime.now().plusDays(1).let { Date.from(it.toInstant()) })
  12.             .sign(algorithm)
  13.     }.fix()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement