authenticate

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

Creates an authentication route that does handle authentication by the specified providers referred by configurations names. null could be used to point to the default provider and could be also mixed with other provider names. Other routes, handlers and interceptors could be nested into this node

The Authentication feature need to be installed first otherwise it will fail with MissingApplicationFeatureException and all providers requested by configurations need to be already registered.

Is is important to note that when optional is set, challenges will be skipped only if no credentials are provided.

To summarize:

optional=false:

optional=true:

Parameters

configurations - names that point to already registered authentication providers

optional - when set, if no auth is provided by the client, the call will continue but with a null Principal

Exceptions

MissingApplicationFeatureException - if no Authentication feature installed first

IllegalArgumentException - if there are no registered providers referred by configurations names