phantom_token_scope
The 'phantom_token_scope' directive specifies the OAuth scopes to be included in the 'WWW-Authenticate' response when access is unauthorized.
Description
The 'phantom_token_scope' directive in the Phantom Token NGINX Module is utilized to define the OAuth scopes that should be included in the 'WWW-Authenticate' header for responses that return an HTTP 401 Unauthorized status. This is particularly important for APIs that require specific scopes for authorization, allowing clients to understand what permissions are needed to access particular resources.
When you define this directive within a location context, it allows the configuration of space-separated scope values that the application must present when requesting access. For instance, if the configured scopes include 'read' and 'write', the module will generate a response header in the format: WWW-Authenticate: Bearer realm="example", scope="read write". This informs clients that they should include these scopes in subsequent requests to gain necessary permissions.
The correct utilization of this directive improves API security by informing the requester about required scopes before they may attempt to interact with protected resources. Without proper scope definition, clients may not be aware of the required permissions, possibly leading to repeated 401 errors until they understand the necessary scopes needed for authorization.
Config Example
location /api {
phantom_token_scope read write;
}Ensure that scopes defined are valid and correspond to those recognized by the authorization server.
Misconfiguration may lead to insufficient permissions being granted and result in authorization failures.