apiKey
fun AuthenticationConfig.apiKey(name: String? = null, configure: ApiKeyAuthenticationProvider.Configuration.() -> Unit)(source)
Installs an API Key authentication mechanism.
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.
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.
inline fun <P : Any> apiKey(name: String, configure: TypedApiKeyAuthConfig<P>.() -> Unit): SimpleAuthenticationScheme<P>(source)
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) }
}
}Content copied to clipboard
Parameters
name
name that identifies the authentication scheme.
configure
configures API key authentication for this scheme.