Move packages + remove circular dependencies
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
package be.simplenotes.domain.security
|
||||
|
||||
import be.simplenotes.types.PersistedUser
|
||||
import com.auth0.jwt.exceptions.JWTVerificationException
|
||||
|
||||
data class JwtPayload(val userId: Int, val username: String) {
|
||||
constructor(user: PersistedUser) : this(user.id, user.username)
|
||||
}
|
||||
|
||||
class JwtPayloadExtractor(private val jwt: SimpleJwt) {
|
||||
operator fun invoke(token: String): JwtPayload? = try {
|
||||
val decodedJWT = jwt.verifier.verify(token)
|
||||
val id = decodedJWT.getClaim(userIdField).asInt() ?: null
|
||||
val username = decodedJWT.getClaim(usernameField).asString() ?: null
|
||||
id?.let { username?.let { JwtPayload(id, username) } }
|
||||
} catch (e: JWTVerificationException) {
|
||||
null
|
||||
} catch (e: IllegalArgumentException) {
|
||||
null
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user