Membrane API Gateway returns 401 Unauthorized or 403 Forbidden with a link to this page when the apiKey plugin rejects a request in the request flow. The request either carries no API key, or the key is not known to any of the configured key stores.
The response contains the status 401 or 403, a detail that tells the two cases apart, the problem type https://membrane-api.io/problems/security/authorization-denied and a link to this page. The type security with the subtype authorization-denied means that a security plugin refused access to the API.
| Status | Detail |
|---|---|
401 | Tried to access API key protected resource without key. |
403 | The provided API key is invalid. |
The apiKey plugin reads the key from the request with its extractors. The first extractor that finds a key wins. Without extractors, the key is read from the X-Api-Key header. The key is then looked up in the configured stores, for example a simple list, an apiKeyFileStore, a databaseApiKeyStore or a mongoDBApiKeyStore.
api:
port: 2000
flow:
- apiKey:
stores:
- simple:
- secret:
value: aed8bcc4-7c83-44d5-8789-21e4024ac873
extractors:
- header: X-Api-Key
target:
url: https://api.predic8.de
api:
port: 2000
flow:
- apiKey:
stores:
- simple:
- secret:
value: aed8bcc4-7c83-44d5-8789-21e4024ac873
extractors:
- header: X-Api-Key
target:
url: https://api.predic8.de
The request carries no key where the extractors look for one. A common mistake is sending the key in a different header or as a query parameter while the plugin only reads the X-Api-Key header.
The key was found in the request, but none of the configured stores contains it. Check for typos, whitespace and keys that were removed from the store.
Without at least one store next to the apiKey plugin, no key can be found, so every request with a key is rejected.
If a store fails while it looks up the key, for example because the database is unreachable or the key file cannot be read, the error is ignored and the key counts as not found. If valid keys are suddenly rejected, check the store.
X-Api-Key.To let requests without a valid key pass while still extracting keys and scopes, set required: false:
api:
port: 2000
flow:
- apiKey:
required: false
stores:
- simple:
- secret:
value: aed8bcc4-7c83-44d5-8789-21e4024ac873
target:
url: https://api.predic8.de
api:
port: 2000
flow:
- apiKey:
required: false
stores:
- simple:
- secret:
value: aed8bcc4-7c83-44d5-8789-21e4024ac873
target:
url: https://api.predic8.de
Unlike most errors, the details and the link to this page are sent for this error even when Membrane runs in production mode. Setting production: true in the configuration document does not remove them. The detail only states whether the key was missing or invalid and does not reveal the configured keys.
Configuration reference:
Tutorials with runnable examples:
Still stuck? See the troubleshooting guide or ask on GitHub Issues. For commercial support, contact info@predic8.de.