Created
January 30, 2024 06:21
-
-
Save Kasun002/31ab9fe8e3d8709d6790aaa1357305b9 to your computer and use it in GitHub Desktop.
Configure Keycloak with PG SQL for role based authentication
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '3.4' | |
volumes: | |
postgres_data: | |
driver: local | |
services: | |
postgres: | |
image: postgres:14.1 | |
container_name: keycloak-nodejs-example-postgres | |
volumes: | |
- postgres_data:/var/lib/postgresql/data | |
environment: | |
POSTGRES_PASSWORD: root | |
POSTGRES_DB: keycloak | |
POSTGRES_USER: keycloak | |
keycloak: | |
image: jboss/keycloak:15.0.2 | |
container_name: keycloak-nodejs-example-keycloak | |
environment: | |
DB_VENDOR: POSTGRES | |
DB_ADDR: postgres | |
DB_DATABASE: keycloak | |
DB_USER: keycloak | |
DB_PASSWORD: root | |
KEYCLOAK_USER: admin | |
KEYCLOAK_PASSWORD: admin | |
command: | |
- "-Dkeycloak.profile.feature.upload_scripts=enabled" | |
- "-Dkeycloak.migration.action=import" | |
- "-Dkeycloak.migration.provider=dir" | |
- "-Dkeycloak.migration.dir=/opt/jboss/keycloak/import" | |
- "-Dkeycloak.migration.strategy=OVERWRITE_EXISTING" | |
ports: | |
- 8080:8080 | |
volumes: | |
- "./docker/import_realm_users:/opt/jboss/keycloak/import" | |
depends_on: | |
- postgres |
Author
Kasun002
commented
Jan 30, 2024
•
Role-Based Authentication System
This project implements a role-based authentication system using Node.js, Keycloak, and PostgreSQL.
Steps to Implement
1. Setup PostgreSQL Database
- Install PostgreSQL
- Create a new database
- Create
users
androles
tables - Insert users and roles data
2. Setup Keycloak
- Install Keycloak
- Create a new realm
- Create roles (admin, manager, editor)
- Create users and assign them roles
3. Setup Node.js Application
- Initialize a new Node.js project
- Install necessary packages (
express
,keycloak-connect
,pg
)
4. Integrate Keycloak with Node.js
- Configure
keycloak-connect
middleware in your Node.js application - Protect your routes with Keycloak
5. Implement Role-Based Access Control (RBAC)
- Create middleware to check the user's role
- Use this middleware in your routes
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment