Authentication
A plugin that handles authentication and authorization. Typical usage scenarios include logging in users, granting access to specific resources, and securely transmitting information between parties.
Ktor supports multiple authentications and authorization schemes, including the Basic
and Digest
HTTP authentication schemes, JSON Web Tokens, OAuth, and so on.
A configuration of the Authentication
plugin might look as follows:
Choose and configure an authentication provider. The code snippet below shows how to create the
basic
provider:install(Authentication) {
basic("auth-basic") {
// Configure basic authentication
}
}Content copied to clipboardProtect a desired resource using the io.ktor.server.routing.Route.authenticate function that accepts a name of the authentication provider:
routing {
authenticate("auth-basic") {
get("/orders") {
// ...
}
}
}Content copied to clipboard
You can learn how to configure various authentication providers from Authentication and authorization.
Types
An installation object of the Authentication plugin.