jwt

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.

Report a problem


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.

Report a problem


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) }
}
}

Report a problem

Parameters

name

name that identifies the JWT authentication scheme.

configure

configures JWT authentication for this scheme.