form

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) }
}
}

Report a problem

Parameters

name

name that identifies the Form authentication scheme.

configure

configures Form authentication for this scheme.


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.

Report a problem


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.

Report a problem