bearer
inline fun <P : Any> bearer(name: String, configure: TypedBearerAuthConfig<P>.() -> Unit): SimpleAuthenticationScheme<P>(source)
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) }
}
}Content copied to clipboard
Parameters
name
name that identifies the Bearer authentication scheme.
configure
configures Bearer authentication for this scheme.
fun AuthenticationConfig.bearer(name: String? = null, configure: BearerAuthenticationProvider.Config.() -> Unit)(source)
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.
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.