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:

  1. 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
    }
    }
  2. Protect a desired resource using the io.ktor.server.routing.Routing.authenticate function that accepts a name of the authentication provider:

     routing {
    authenticate("auth-basic") {
    get("/orders") {
    // ...
    }
    }
    }

You can learn how to configure various authentication providers from Authentication and authorization.

Constructors

Link copied to clipboard
constructor(config: AuthenticationConfig)

Types

Link copied to clipboard

Functions

Link copied to clipboard

Configures an already installed plugin.