nginx-keycloak
nginx-keycloak copied to clipboard
Set NGINX as a reverse proxy with Keycloak SSO in front of your web applications.
Nginx Keycloak
Setting NGINX as a reverse proxy with Keycloak SSO in front of your web applications.
Getting started
Configuring Keycloak
-
Set-up
.envand edit variable valuescp .env.example .env -
Start Keycloak
docker-compose up -d keycloak -
Go to
http://localhost:3333and login with your credentials -
In the master realm, we are going to create a client
- In sidebar, click "Clients" and click on the "Create" button. Let's call it
NginxApps. - In
NginxAppsclient parameters :- Add a "Valid Redirect URI" to your app :
http://localhost:3002/*(don't forget clicking "+" button to add the URL, then "Save" button) - Set the "Access type" to
confidential
- Add a "Valid Redirect URI" to your app :
- In the "Credentials" tab, retrieve the "Secret" and set
KEYCLOAK_SECRETin your.envfile
- In sidebar, click "Clients" and click on the "Create" button. Let's call it
-
Go to "Users" in the sidebar and create one. Edit its password in the "Credentials" tab.
Simple user authentication
With this method, being a registered user is sufficient to access your apps.
If you choose this method, you're already set. Just run :
docker-compose up -d nginx app_1
You can now visit http://localhost:3002 to validate the configuration.
Role-based / per-app user authentication
Let's say you want only specific users to be able to access specific apps. We have to create a role for that.
-
In sidebar, click "Clients"
-
Select the
NginxAppsclient and go to the "Roles" tab -
Top right, click the "Add Role" button and create one with name
NginxApps-App1:information_source: 1 role = 1 app
Now we want to attribute this role to our user.
- In sidebar, click "Users"
- Click "Edit" on the user you want to add the role to
- Go to the "Role Mappings" tab
- Select the "Client Roles"
NginxAppsand assign theNginxApps-App1role by selecting it and clicking "Add selected"
In our docker-compose configuration, edit the NGINX configuration mount point to be ./nginx-roles.conf.template instead of ./nginx.conf.template.
: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.
Start NGINX and the app :
docker-compose up -d nginx app_1
You can now visit http://localhost:3002 to validate the configuration.