Microservice with Api Gateway, Eureka Discovery Client and User Service with KeyCloak authentication server
Keycloak is used for managing user authentication and authorization.
- Docker Command to Run Keycloak:
docker run -p 9090:8080 -e KC_BOOTSTRAP_ADMIN_USERNAME=admin -e KC_BOOTSTRAP_ADMIN_PASSWORD=admin quay.io/keycloak/keycloak:26.2.5 start-dev
- Keycloak Admin Console URL: http://localhost:8080/
- Default Admin Credentials:
- Username:
admin - Password:
admin
- Username:
Eureka acts as a service registry for all microservices.
- Eureka Dashboard URL: http://localhost:8761/
The API Gateway provides a single entry point for external clients to access the microservices.
- API Gateway Base URL: http://localhost:8762
The User Service handles user-related operations.
- User Service Base URL (Direct Access - for internal use/testing): http://localhost:8081
All external interactions with the User Service should be routed through the API Gateway.
-
URL:
http://localhost:8762/user/create -
Method:
POST -
Content-Type:
application/json -
Payload Example:
{ "username": "asad123", "password": "12345", "email": "hm.ashad.zaman.123@gmail.com", "firstName": "Ashad123", "lastName": "zaman45", "phone": "01325781959" }
To access protected resources, you'll need an access token from Keycloak.
-
Token Endpoint URL:
http://localhost:8080/realms/refresh-memory-microservice/protocol/openid-connect/token -
Request Method:
POST -
Payload (Form URL-Encoded):
grant_type=password client_id=<your-client-id> username=<your-username> password=<your-password> client_secret=<client_secret>Note: Replace
<your-client-id>and<your-client-secret>with the actual client ID configured in your Keycloak realm (e.g.,refresh-memory-client).
This endpoint requires an access token obtained from Keycloak.
-
URL:
http://localhost:8762/user/me -
Method:
GET -
Authorization Header:
Authorization: Bearer {token}Example:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c