bearer

Creates a typed Bearer authentication scheme with a principal type P.

data class ApiUser(val id: String)

val bearerAuth = bearer<ApiUser>("api-bearer") {
validate { token -> findUserByToken(token) }
}

routing {
authenticateWith(bearerAuth) {
get("/api/me") { call.respondText(call.principal.id) }
}
}

Report a problem

Parameters

name

name that identifies the Bearer authentication scheme.

configure

configures Bearer authentication for this scheme.


Installs the Bearer Authentication provider. Bearer auth requires the developer to provide a custom 'authenticate' function to authorize the token and return the associated principal.

Report a problem


fun AuthenticationConfig.bearer(name: String? = null, description: String? = null, configure: BearerAuthenticationProvider.Config.() -> Unit)(source)

Installs the Bearer Authentication provider with description. Bearer auth requires the developer to provide a custom 'authenticate' function to authorize the token and return the associated principal.

Report a problem