Authorization directives can be used in your schema to define granular authorization rules on the field definition level. Documentation can be found at @authenticated and @requiresScopes.
Current Configuration
In the current router version, the configuration and behavior of authentication have been redesigned. Instead of specifying a configuration per JWKS endpoint, you can now list multiple endpoints where all header rules apply to. Each JWKS endpoint can optionally specify a whitelist of supported JWT algorithms.Configuration
Old Router configuration (< 0.168.1)
Enforce authentication
By default, requests without authentication information are allowed. Only requests with invalid authentication information (e.g. an incorrectly signed token) produce a403 Forbidden response. To disable anonymous requests, use the Authorization configuration:
401 Unauthorized
Authentication information is also available to custom modules. See Access Authenticated Information.
Forwarding authentication headers
By default, the router won’t forward authentication headers to subgraphs, but if desired this can be configured using Proxy capabilities.Refreshing Unknown KIDs on Demand
Whenrefresh_unknown_kid.enabled is set to true, the router will automatically attempt to refresh the JWKS (fetch updated keys) whenever it encounters a valid token with an unknown KID (Key ID). This is useful when key rotation has occurred but the router hasn’t picked up the new keys in its regular refresh cycle.
To prevent overwhelming the JWKS endpoint, this feature includes rate limiting controlled by the following parameters:
burst: Maximum number of refreshes allowed without waiting. Internally, the router keeps a counter of available burst tokens. Each time theintervalelapses, one token is replenished, up to theburstlimit.interval: The time that must elapse between replenishing burst tokens, until theburstlimit is reached.max_wait: Maximum time a refresh is allowed to wait. If the computed wait would exceed this value, the request is rejected immediately with a 401 Unauthorized status instead of waiting.
Rate Limiting Example
Let’s examine how rate limiting works with these settings:- First request: JWKS refreshed immediately; 1 burst token is consumed.
- Second request: Waits for 30s (interval × 1); a token is replenished after 30s.
- Third request: Waits for 60s (interval × 2); a token is replenished after another 30s.
- Fourth request: Waits for 90s (interval × 3); a token is replenished after another 30s.
- Fifth request: Fails immediately (would require 120s wait > max_wait) with 401 Unauthorized.
- Sixth request: Fails immediately (would require 150s wait > max_wait) with 401 Unauthorized.
interval elapses. If burst were set to 2, the second request would also pass immediately.
The max_wait setting prevents excessive wait times. In this example, since the 5th and 6th requests would require waiting longer than the configured max_wait of 110s, they immediately return with a 401 Unauthorized status instead of attempting to refresh.