This project provides a microservice for OIDC authentication with Nginx. It is designed as a reverse proxy layer that enforces authentication before giving access to backend services (HTTP or WebSocket). The Nginx configuration files included in the project let you secure any service by plugging it behind the OIDC auth gateway.
You can run the microservice via Docker:
docker-compose up --buildThis starts:
- Nginx on ports
8000(auth endpoints) and8001(protected example service). - An auth backend handling OIDC logic (login, token validation, conditions).
- Example mock services to demonstrate how to protect an API and a WebSocket server.
- Copy the provided configuration snippets (
auth_service.conf,use_auth.conf). - Adjust the URLs (
proxy_pass,server_name, etc.) for your own service. - Include the config in your
nginx.confto enable the OIDC auth check.
The flow is:
- Requests to your service go through Nginx.
auth_requestsends them to/sso/check.- If authorized → request is proxied to your backend.
- If unauthorized → user is redirected to
/sso/login.
The auth backend /sso/check endpoint supports conditional checks with the X-Conditions header, which Nginx sets using $auth_params.
Example:
location /ws {
set $auth_params "not__service=QAE";
auth_request /sso/check;
error_page 401 = @login;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://my_websocket_backend;
}Here:
$auth_paramssends conditions to the backend.- Keys can use
not__for negation. - The backend checks decoded token claims against these conditions and returns
200,401, or403accordingly.
This makes it possible to restrict access to certain users, roles, or services based on claims in the OIDC token.
GET /up→ health check ({"status":"ok", "version":"1.0"})GET /sso/login→ starts the login flowPOST /sso/check→ internal check used by Nginxauth_request- Protected service examples available at port
8001(HTTP + WebSocket)
- The
authbackend must implement OIDC logic (token validation, claim checking). - The provided configs are examples: adjust them to fit your services.
$auth_paramsallows attribute-based access control (ABAC) by passing conditions to the backend.
MIT