Quick overview
This workflow exposes a single n8n webhook as an API gateway that authenticates requests against Stripe customer metadata, authorizes access with role-based permissions, enforces per-role rate limits using Redis, and forwards allowed requests to internal n8n webhook endpoints.
How it works
- Receives a POST request on the n8n webhook with an API key, target route, method, and payload.
- Looks up the Stripe customer whose metadata contains the provided API key and resolves the requester role from Stripe customer metadata.
- Rejects unauthenticated requests with a 401 JSON response when no matching Stripe customer is found.
- Checks the requested route against a configured route-to-roles permission map and rejects disallowed access with a 403 JSON response.
- Increments a per-API-key counter in Redis for the current time window and compares it to the configured per-role limit.
- Rejects over-limit requests with a 429 JSON response and a Retry-After header, or forwards allowed requests to the mapped internal n8n webhook URL.
- Returns the internal workflow response to the client and includes X-RateLimit-Limit and X-RateLimit-Remaining headers.
Setup
- Add Stripe API credentials with permission to search customers and ensure each Stripe customer includes metadata.apiKey and metadata.role (admin, user, or readonly).
- Add Redis credentials and ensure your Redis instance is reachable from n8n.
- Update the gateway configuration to match your API design, including routePermissions, rateLimits, rateLimitWindowSeconds, and internalWorkflowMap URLs.
- Configure your internal workflows to expose the target webhook endpoints and accept the forwarded payload (including the _gateway context object).
- Copy the webhook URL for this workflow’s /gateway endpoint and point your client applications to it instead of calling internal workflows directly.