auth_jwt_key

The `auth_jwt_key` directive specifies the key used for decoding and verifying JWTs in NGINX.

Syntaxauth_jwt_key key_string;
Defaultnone
Contexthttp, server, location
Arguments1

Description

The auth_jwt_key directive is an essential component of the JWT authentication process in NGINX, allowing the module to decode and validate incoming JWTs issued by a trusted authority. This key is provided in a binhex format and is critical for ensuring the integrity and authenticity of the JWT being validated. When the JWT is received in an HTTP request, NGINX uses this key to perform cryptographic operations to confirm that the token has not been tampered with and that it was indeed issued by a trusted signer.

The context in which auth_jwt_key can be used includes the http, server, and location blocks within the NGINX configuration. This flexibility allows for the configuration of different keys for various scopes of requests. An administrator may define different keys for different routes or services based on security requirements and the specific JWTs being handled. The directive takes a single argument – the key string that will be used for the verification process, facilitating secure authentication flows across distributed systems.

When utilized correctly, the auth_jwt_key directive enhances the security of web applications by enforcing authentication through well-defined JWTs, which include claims that can be optionally extracted for further processing. Combining this directive with others, such as auth_jwt_enabled and auth_jwt_redirect, allows for comprehensive management of authentication logic and user experience by specifying fallback behavior upon authentication failures.

Config Example

location /protected {
    auth_jwt_enabled on;
    auth_jwt_key "your_base64_encoded_key";
    auth_jwt_redirect on;
    auth_jwt_loginurl /login;
}

Ensure the key is provided in the correct format (binhex).

Be cautious when configuring keys for multiple locations to prevent conflicts.

Remember to define the key before using related JWT directives.

← Back to all directives