authenticate

fun Route.authenticate(vararg configurations: String? = arrayOf(null), optional: Boolean = false, build: Route.() -> Unit): Route(source)

Creates a route that allows you to define authorization scope for application resources. This function accepts names of authentication providers defined in the Authentication plugin configuration.

Report a problem

Parameters

configurations

names of authentication providers defined in the Authentication plugin configuration.

optional

when set, if the client provides no authentication, a call continues but with a null authenticated value.

See also

Throws

if there are no registered providers referred by configurations names.


fun Route.authenticate(vararg configurations: String? = arrayOf(null), strategy: AuthenticationStrategy, build: Route.() -> Unit): Route(source)

Creates a route that allows you to define authorization scope for application resources. This function accepts names of authentication providers defined in the Authentication plugin configuration.

When combined with other route-scoped guard plugins such as io.ktor.server.plugins.ratelimit.rateLimit, the relative execution order follows route nesting: interceptors on parent routes run before interceptors on child routes. To use a principal in a rate limit io.ktor.server.plugins.ratelimit.RateLimitProviderConfig.requestKey, nest rateLimit inside authenticate.

Report a problem

Parameters

configurations

names of authentication providers defined in the Authentication plugin configuration.

strategy

defines resolution strategy for nested authentication providers. AuthenticationStrategy.Optional - if the client provides no authentication, a call continues but with a null authenticated value. AuthenticationStrategy.FirstSuccessful - client must provide authentication data for at least one provider registered for this route AuthenticationStrategy.Required - client must provide authentication data for all providers registered for this route with this strategy

See also

Throws

if there are no registered providers referred by configurations names.