auth_jwt_algorithm

The `auth_jwt_algorithm` directive specifies the algorithm used for verifying JSON Web Tokens (JWTs) in NGINX.

Syntaxauth_jwt_algorithm algorithm;
Defaultnone
Contexthttp, server, location
Arguments1

Description

The auth_jwt_algorithm directive is integral to the JWT authentication process in NGINX, as it determines the cryptographic algorithm used for validating the signature of a JWT submitted with requests. This parameter accepts one of several predefined algorithms, including HS256, HS384, HS512, RS256, RS384, and RS512. Depending on the algorithm chosen, the server will apply the corresponding method to verify that the JWT has not been tampered with and is indeed valid. This is crucial for ensuring the security of web applications that rely on token-based authentication.

This directive can be set at various levels of configuration: http, server, and location, which allows for flexible application throughout different parts of the server's configuration. When a JWT is received, the configured algorithm determines how the NGINX server will decode the token's signature and validate it against the secret key or public key as established by the auth_jwt_key directive. If the algorithm does not match the JWT's signing method, validation will fail, leading to authentication failure for the user.

It's important for users to choose the appropriate algorithm that aligns with their security requirements and the method used to create the JWTs. Each algorithm has different strength levels based on their cryptographic design. If no algorithm is specified, the verification process will not be secure, making it essential to configure this directive correctly.

Config Example

location /protected {
    auth_jwt_enabled on;
    auth_jwt_algorithm HS256;
    auth_jwt_key /path/to/key;
}

Ensure that the algorithm matches the one used when signing the JWT, otherwise authentication will fail.

Using an insecure algorithm may lead to vulnerabilities in token validation; prefer strong algorithms like RS256 or HS512.

If the algorithm is misconfigured or left unset, JWT validation will not occur.

← Back to all directives