basic
fun AuthenticationConfig.basic(name: String? = null, configure: BasicAuthenticationProvider.Config.() -> Unit)(source)
Installs the basic Authentication provider. You can use basic authentication for logging in users and protecting specific routes. To learn how to configure it, see Basic authentication.
fun AuthenticationConfig.basic(name: String? = null, description: String? = null, configure: BasicAuthenticationProvider.Config.() -> Unit)(source)
Installs the basic Authentication provider with description. You can use basic authentication for logging in users and protecting specific routes. To learn how to configure it, see Basic authentication.
inline fun <P : Any> basic(name: String, configure: TypedBasicAuthConfig<P>.() -> Unit): SimpleAuthenticationScheme<P>(source)
Creates a typed Basic authentication scheme with a principal type P.
data class User(val name: String)
val userAuth = basic<User>("user-auth") {
validate { credentials -> findUser(credentials.name, credentials.password) }
}
routing {
authenticateWith(userAuth) {
get("/me") { call.respondText(call.principal.name) }
}
}Content copied to clipboard
Parameters
name
name that identifies the Basic authentication scheme.
configure
configures Basic authentication for this scheme.