form
inline fun <P : Any> form(name: String, configure: TypedFormAuthConfig<P>.() -> Unit): SimpleAuthenticationScheme<P>(source)
Creates a typed Form authentication scheme.
The validate callback returns a principal of type P. Use the returned scheme with authenticateWith to protect routes and access principal without casts.
data class User(val name: String)
val formAuth = form<User>("login-form") {
validate { credentials -> findUser(credentials.user, credentials.password) }
}
routing {
authenticateWith(formAuth) {
get("/dashboard") { call.respondText(call.principal.name) }
}
}Content copied to clipboard
Parameters
name
name that identifies the Form authentication scheme.
configure
configures Form authentication for this scheme.
fun AuthenticationConfig.form(name: String? = null, configure: FormAuthenticationProvider.Config.() -> Unit)(source)
Installs the form-based Authentication provider. Form-based authentication uses a web form to collect credential information and authenticate a user. To learn how to configure it, see Form-based authentication.
fun AuthenticationConfig.form(name: String? = null, description: String? = null, configure: FormAuthenticationProvider.Config.() -> Unit)(source)
Installs the form-based Authentication provider with description. Form-based authentication uses a web form to collect credential information and authenticate a user. To learn how to configure it, see Form-based authentication.