apiKey

Installs an API Key authentication mechanism.

Report a problem

Parameters

name

optional name for this authentication provider. If not specified, a default name will be used.

configure

configuration block for setting up the API Key authentication provider.


fun AuthenticationConfig.apiKey(name: String? = null, description: String? = null, configure: ApiKeyAuthenticationProvider.Configuration.() -> Unit)(source)

Installs an API Key authentication mechanism.

Report a problem

Parameters

name

optional name for this authentication provider. If not specified, a default name will be used.

description

optional description for this authentication provider.

configure

configuration block for setting up the API Key authentication provider.


Creates a typed API key authentication scheme with principal type P.

data class ApiKeyPrincipal(val key: String)

val apiKeyAuth = apiKey<ApiKeyPrincipal>("api-key") {
validate { apiKey ->
if (apiKey == "valid") ApiKeyPrincipal(apiKey) else null
}
}

routing {
authenticateWith(apiKeyAuth) {
get("/protected") { call.respondText(call.principal.key) }
}
}

Report a problem

Parameters

name

name that identifies the authentication scheme.

configure

configures API key authentication for this scheme.