Skip to content

shreyasY2k/centralized-keycloak-auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Centralized UAM (User Access Management) Application

This repository contains code for a Centralized User Access Management (UAM) application. It includes a Node.js Express server for managing posts, integrated with Keycloak for authentication and authorization.

Run In Postman

Prerequisites

  • Docker installed on your machine
  • Node.js installed on your machine
  • A Keycloak instance running (you can use the provided docker-compose.yaml file)
  • An .env file with the following environment variables posts-api directory:
PORT=3000
KEYCLOAK_INTROSPECTION_URL=http://localhost:8080/auth/realms/your-realm-name/protocol/openid-connect/token/introspect
CLIENT_ID=your-client-id
CLIENT_SECRET=your-client-secret
  • Another .env file with the following environment variables in the Keycloak directory:
PG_DB=keycloak
PG_USER=keycloak_user
PG_PASSWORD=keycloak_password
KEYCLOAK_ADMIN=your-admin-username
KEYCLOAK_ADMIN_PASSWORD=your-admin-password

Replace your-realm-name, your-client-id, and your-client-secret with your actual Keycloak realm name, client ID, and client secret respectively.

Setup

  1. Clone this repository:
cd Centralized-UAM
  1. Navigate to the Keycloak directory and run Keycloak using Docker:
cd Keycloak
docker-compose up -d
  1. Create a .env file in the posts-api directory with the required environment variables as mentioned in the Prerequisites section.

  2. Install dependencies and run the posts API:

cd posts-api
npm install
node index.js
  1. Optionally, if you are using domain name with nginx, you can use the nginx.conf file to configure the reverse proxy as shown in Keycloak directory.

Usage

Refer to this blog post for detailed instructions on how to setup keycloak and use the application.

You can also refer to the Keycloak documentation for more information. Once the application is running, you can access the following endpoints:

  • GET /admin: Get admin endpoint.
  • GET /users: Get users endpoint.
  • GET /posts: Get posts endpoint.

Make sure to include the access token in the Authorization header for each request.

Contributing

Contributions are welcome! Feel free to open issues or pull requests.