jwt
fun AuthenticationConfig.jwt(name: String? = null, configure: JWTAuthenticationProvider.Config.() -> Unit)(source)
Installs the JWT Authentication provider. JWT (JSON Web Token) is an open standard that defines a way for securely transmitting information between parties as a JSON object. To learn how to configure it, see JSON Web Tokens.
fun AuthenticationConfig.jwt(name: String? = null, description: String? = null, configure: JWTAuthenticationProvider.Config.() -> Unit)(source)
Installs the JWT Authentication provider with description. JWT (JSON Web Token) is an open standard that defines a way for securely transmitting information between parties as a JSON object. To learn how to configure it, see JSON Web Tokens.
inline fun <P : Any> jwt(name: String, configure: TypedJwtAuthConfig<P>.() -> Unit): SimpleAuthenticationScheme<P>(source)
Creates a typed JWT authentication scheme with principal type P.
data class JwtUser(val name: String)
val jwtAuth = jwt<JwtUser>("jwt-auth") {
verifier(issuer = "https://issuer.example", audience = "my-audience", algorithm = Algorithm.HMAC256("secret"))
validate { credential ->
if (credential.audience.contains("my-audience")) {
JwtUser(credential.payload.subject)
} else {
null
}
}
}
routing {
authenticateWith(jwtAuth) {
get("/profile") { call.respondText(call.principal.name) }
}
}Content copied to clipboard
Parameters
name
name that identifies the JWT authentication scheme.
configure
configures JWT authentication for this scheme.