Separate views into a maven module

This commit is contained in:
2020-10-24 01:25:25 +02:00
parent 536c6e7b79
commit 8b8dbd6fe5
37 changed files with 255 additions and 227 deletions
@@ -1,6 +1,7 @@
package be.simplenotes.domain.security
import be.simplenotes.config.JwtConfig
import be.simplenotes.types.LoggedInUser
import com.auth0.jwt.JWT
import com.auth0.jwt.JWTVerifier
import com.auth0.jwt.algorithms.Algorithm
@@ -15,9 +16,9 @@ class SimpleJwt(jwtConfig: JwtConfig) {
private val algorithm = Algorithm.HMAC256(jwtConfig.secret)
val verifier: JWTVerifier = JWT.require(algorithm).build()
fun sign(jwtPayload: JwtPayload): String = JWT.create()
.withClaim(userIdField, jwtPayload.userId)
.withClaim(usernameField, jwtPayload.username)
fun sign(loggedInUser: LoggedInUser): String = JWT.create()
.withClaim(userIdField, loggedInUser.userId)
.withClaim(usernameField, loggedInUser.username)
.withExpiresAt(getExpiration())
.sign(algorithm)