{"id":22018463,"url":"https://github.com/flavienbwk/nginx-keycloak","last_synced_at":"2025-07-23T21:33:46.031Z","repository":{"id":43357702,"uuid":"466123654","full_name":"flavienbwk/nginx-keycloak","owner":"flavienbwk","description":"Set NGINX as a reverse proxy with Keycloak SSO in front of your web applications.","archived":false,"fork":false,"pushed_at":"2024-09-21T22:30:46.000Z","size":33,"stargazers_count":23,"open_issues_count":0,"forks_count":5,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-31T05:51:08.728Z","etag":null,"topics":["docker","keycloak","nginx","sso"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/flavienbwk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-03-04T12:57:43.000Z","updated_at":"2025-03-25T00:01:25.000Z","dependencies_parsed_at":"2022-08-19T20:21:20.110Z","dependency_job_id":null,"html_url":"https://github.com/flavienbwk/nginx-keycloak","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flavienbwk%2Fnginx-keycloak","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flavienbwk%2Fnginx-keycloak/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flavienbwk%2Fnginx-keycloak/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flavienbwk%2Fnginx-keycloak/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flavienbwk","download_url":"https://codeload.github.com/flavienbwk/nginx-keycloak/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252805805,"owners_count":21807083,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","keycloak","nginx","sso"],"created_at":"2024-11-30T05:12:16.039Z","updated_at":"2025-05-07T03:26:59.889Z","avatar_url":"https://github.com/flavienbwk.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Nginx Keycloak\n\n[![Docker build](https://github.com/flavienbwk/nginx-keycloak/actions/workflows/docker-build.yml/badge.svg)](https://github.com/flavienbwk/nginx-keycloak/actions/workflows/docker-build.yml)\n[![Test](https://github.com/flavienbwk/nginx-keycloak/actions/workflows/test-keycloak-setup.yml/badge.svg)](https://github.com/flavienbwk/nginx-keycloak/actions/workflows/test-keycloak-setup.yml)\n\nSetting NGINX as a reverse proxy with Keycloak SSO in front of your web applications.\n\n## Getting started\n\n### Configuring Keycloak\n\n1. Set-up `.env` and edit variable values\n\n    ```bash\n    cp .env.example .env\n    ```\n\n2. Start Keycloak\n\n    ```bash\n    docker compose up -d keycloak\n    ```\n\n3. Go to `http://localhost:3333` and login with your credentials\n\n4. In the [master realm](http://localhost:3333/auth/admin/master/console/#/realms/master), we are going to create a client\n\n    1. In sidebar, click [\"Clients\"](http://localhost:3333/auth/admin/master/console/#/realms/master/clients) and click on the \"Create\" button. Let's call it `NginxApps`.\n    2. In `NginxApps` client parameters :\n       1. Add a \"Valid Redirect URI\" to your app : `http://localhost:3002/*` (don't forget clicking \"+\" button to add the URL, then \"Save\" button)\n       2. Set the \"Access type\" to `confidential`\n    3. In the \"Credentials\" tab, retrieve the \"Secret\" and **set `KEYCLOAK_SECRET` in your `.env`** file\n\n5. Go to [\"Users\"](http://localhost:3333/auth/admin/master/console/#/realms/master/users) in the sidebar and create one. Edit its password in the \"Credentials\" tab.\n\n6. (optional) Edit max token lifespan going to \"Realm settings\" \u003e \"SSO Session Max\" and set the desired time before the user token expires.\n\n### Simple user authentication\n\nWith this method, being a registered user is sufficient to access your apps.\n\nIf you choose this method, you're already set. Just run :\n\n```bash\ndocker compose up -d nginx app_1\n```\n\nYou can now visit `http://localhost:3002` to validate the configuration.\n\n### Role-based / per-app user authentication\n\nLet's say you want only specific users to be able to access specific apps. We have to create a role for that.\n\n1. In sidebar, click \"Clients\"\n2. Select the `NginxApps` client and go to the \"Roles\" tab\n3. Top right, click the \"Add Role\" button and create one with name `NginxApps-App1`\n\n    :information_source: 1 role = 1 app\n\nNow we want to attribute this role to our user.\n\n1. In sidebar, click \"Users\"\n2. Click \"Edit\" on the user you want to add the role to\n3. Go to the \"Role Mappings\" tab\n4. Select the \"Client Roles\" `NginxApps` and assign the `NginxApps-App1` role by selecting it and clicking \"Add selected\"\n\nIn our [docker compose](./docker compose.yml) configuration, edit the NGINX configuration mount point to be `./nginx-roles.conf.template` instead of `./nginx.conf.template`.\n\n:information_source: If you want to name your role differently, you can edit the expected name in `./nginx-roles.conf.template` in the `contains(client_roles, \"NginxApps-App1\")` line.\n\nStart NGINX and the app :\n\n```bash\ndocker compose up -d nginx app_1\n```\n\nYou can now visit `http://localhost:3002` to validate the configuration.\n\n## Credits\n\n- [Configure NGINX and Keycloak to enable SSO for proxied applications](https://kevalnagda.github.io/configure-nginx-and-keycloak-to-enable-sso-for-proxied-applications)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflavienbwk%2Fnginx-keycloak","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflavienbwk%2Fnginx-keycloak","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflavienbwk%2Fnginx-keycloak/lists"}