Membrane API Gateway returns 500 Internal Server Error with the detail Error handling request! when the OAuth2 client plugin oauth2Resource2 throws an unexpected exception while it handles a request.
The response contains the status 500 Internal Server Error, the detail Error handling request!, the problem type https://membrane-api.io/problems/internal and a link to this page. The type internal means that the gateway could not complete the processing of the message. In production mode, the title is replaced by Internal Server Error and the details are left out.
The oauth2Resource2 plugin protects an API with an OAuth2 or OpenID Connect login. It redirects unauthenticated users to the authorization server, handles the callback and keeps the login in a session. OAuth2 protocol errors are handled separately and do not end up here, so this error usually points to the gateway configuration or environment, or to a bug in Membrane. For the flow in general, see the authorization code flow tutorial.
The query string of the callback, or of a redirect back from the login, cannot be parsed, for example because a parameter appears twice or has no =.
Before the login redirect, the plugin stores the original request in the session. If that session entry is missing or corrupt, it cannot be read back.
The login URL of the authorization server, or the public URL of the gateway, cannot be determined.
A remote session store, for example Redis or Memcached, failed while the session was read.
error level. In production, use the log key of the response to find it.oauth2Resource2 is reachable and returns a valid discovery document and login URL.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 ---. The title then reads Internal Server Error, and the details and the link to this page are left out. If the response contains a log key, search the gateway log for it to find the full error message.
Configuration reference:
Tutorials with runnable examples:
Still stuck? See the troubleshooting guide or ask on GitHub Issues. For commercial support, contact info@predic8.de.