Membrane API Gateway returns 401 Unauthorized with a link to this page when the jwtAuth plugin hits an unexpected error while it reads or checks the JWT. The cause is either a malformed token from the client or a gateway that cannot load its keys.
The response contains the status 401 Unauthorized, a detail with the underlying error message, the problem type https://membrane-api.io/problems/security and a link to this page. The type security means that a security plugin refused access to the API.
A request without any token does not produce this error. That case is reported under security/jwt-auth with the detail Could not retrieve JWT.
The header or payload part of the token contains characters that are not valid Base64URL, for example because it was changed or double-encoded.
The token header contains "kid": null instead of a key ID.
The keys from jwksUris could not be loaded when the request arrived, for example because the identity provider is unreachable, DNS fails, or an outbound proxy blocks the request.
No key is configured for jwtAuth, or none of the configured keys could be resolved.
jwksUris is reachable from the gateway and returns a valid JWK set, or configure the keys inline.api:
port: 4000
flow:
- jwtAuth:
expectedAud: order
jwks:
jwksUris: https://login.microsoftonline.com/common/discovery/keys
target:
url: http://localhost:3000
api:
port: 4000
flow:
- jwtAuth:
expectedAud: order
jwks:
jwksUris: https://login.microsoftonline.com/common/discovery/keys
target:
url: http://localhost:3000
You can test from the gateway host whether the JWKS URL is reachable, for example with curl https://login.microsoftonline.com/common/discovery/keys.
By default, Membrane runs in development mode and adds details to error responses that help you find the problem. These details may reveal information about your setup. In production, turn them off:
configuration:
production: trueconfiguration: production: true
Add the configuration document to your apis.yaml and separate it from the APIs with ---.
Configuration reference:
Tutorials with runnable examples:
Still stuck? See the troubleshooting guide or ask on GitHub Issues. For commercial support, contact info@predic8.de.