Membrane API Gateway returns 401 Unauthorized with a link to this page when the jwtAuth plugin finds no usable JWT or no matching key for it. The request is rejected in the request flow and never reaches the backend.
The response contains the status 401 Unauthorized, a detail that names the problem, 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.
The jwtAuth plugin reads the token from the request, by default from the Authorization header with the Bearer prefix. It uses the kid in the token header to pick a key from jwks, verifies the signature and checks the claims. Keys can be configured inline or loaded from jwksUris:
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
The header the JWT is read from is missing. Check that the client sends Authorization: Bearer <token>. If the token comes in another header, configure a headerJwtRetriever with the right header and removeFromValue.
The token does not consist of three parts separated by dots. It may be truncated, or the client sent an opaque access token instead of a JWT.
The header or payload part of the token does not decode to a JSON object.
The token's header has no kid. The key ID is required to choose the verification key.
No key in jwks has the token's kid. The token comes from a different identity provider, or the provider rotated its keys and the new key is not in the configured JWKS.
Other errors while reading the token are reported under retrieving-jwt, and tokens that fail verification under jwt-validation-failed.
Authorization: Bearer <token>, issued by the expected identity provider.jwks, inline or via jwksUris, contains the provider's current signing keys, including the kid the tokens use.headerJwtRetriever.See the JWT tutorial for a complete example.
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.