auth_jwt_extract_response_claims

The `auth_jwt_extract_response_claims` directive extracts specified claims from a JWT and adds them to the response headers.

Syntaxauth_jwt_extract_response_claims claim_name1 claim_name2 ...;
Defaultnone
Contexthttp, server, location
Arguments1+

Description

The auth_jwt_extract_response_claims directive is used in NGINX to extract specific claims from a JSON Web Token (JWT) and place them in the response headers sent back to the client. This capability is particularly useful for passing authentication or authorization details from the server to the client after successful verification of the JWT. The claims that need to be extracted are specified as a space-separated list of claim names, enabling fine-tuned control over the information that is shared in the response headers.

When NGINX processes a request, it verifies the JWT based on the configuration settings. Once a JWT is validated, the auth_jwt_extract_response_claims directive allows for the extraction of specified claims, which are then made accessible as response headers. This directive provides a simple mechanism to ensure that relevant claims are returned to the client, which can be beneficial for various client-side operations such as UI updates or API interactions.

In summary, this directive enhances the JWT functionality by enabling the server to selectively provide specific claims in the response, which can be essential for maintaining stateless authentication and improving client-server interactions.

Config Example

location /api {
    auth_jwt_enabled on;
    auth_jwt_extract_response_claims sub email;
}

Ensure that the claims specified exist in the JWT; otherwise, they will not be extracted.

Watch out for header size limits; too many claims may lead to oversized responses.

Receiving clients should be prepared to handle the specified response headers properly.

← Back to all directives