KEYCLOAK API
KEYCLOAK API
Introduction
This guide provides detailed instructions on how to interact with the Keycloak REST API using
Postman. It covers essential operations for managing users and groups, including retrieving user
and group information, getting group memberships, and more.
Prerequisites
• Keycloak server running (this guide uses a local instance at http://localhost:8080)
• Postman installed for API testing
• A realm created in Keycloak (this guide uses “poc-realm”)
• A client configured in the realm (this guide uses “node-api”)
• Admin user credentials
Environment Setup
Keycloak Configuration Details
• Server URL: http://localhost:8080
• Realm: poc-realm
• Client ID: node-api
• Client Secret: 4ngr5nmrM5Q8xrKWJwRzY4GEIMK1WYga
• Admin Username: admin-user
• Admin Password: 1234
http://localhost:8080/auth/realms/poc-realm/protocol/openid-
connect/token
o Key: Content-Type
o Value: application/x-www-form-urlencoded
4. Add the following key-value pairs in the Body tab (x-www-form-urlencoded):
o client_id: node-api
o client_secret: 4ngr5nmrM5Q8xrKWJwRzY4GEIMK1WYga
o grant_type: password
o username: admin-user
o password: 1234
5. Send the request
Example response:
{
"access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...",
"expires_in": 300,
"refresh_expires_in": 1800,
"refresh_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...",
"token_type": "bearer",
"not-before-policy": 0,
"session_state": "a1234567-1234-1234-1234-123456789abc",
"scope": "profile email"
}
API Operations
1. Get All Users
Retrieves a list of all users in the realm.
1. Create a new GET request in Postman
http://localhost:8080/auth/admin/realms/poc-realm/users
o Key: Authorization
o Value: Bearer your-access-token-here (replace with the actual token)
4. Optional query parameters:
http://localhost:8080/auth/admin/realms/poc-realm/groups
o Key: Authorization
o Value: Bearer your-access-token-here (replace with the actual token)
Example response:
[
{
"id": "773fad75-4c5f-4332-a64a-c7a5c7b101c5",
"name": "poc",
"path": "/poc",
"subGroupCount": 0,
"subGroups": [],
"access": {
"view": true,
"viewMembers": true,
"manageMembers": true,
"manage": true,
"manageMembership": true
}
},
...
]
2. Set the URL (replace the group ID with your actual group ID):
http://localhost:8080/auth/admin/realms/poc-realm/groups/773fad75-4c5f-
4332-a64a-c7a5c7b101c5
o Key: Authorization
o Value: Bearer your-access-token-here (replace with the actual token)
2. Set the URL (replace the group ID with your actual group ID):
http://localhost:8080/auth/admin/realms/poc-realm/groups/773fad75-4c5f-
4332-a64a-c7a5c7b101c5/members
o Key: Authorization
o Value: Bearer your-access-token-here (replace with the actual token)
4. Optional query parameters:
2. Set the URL (replace the user ID with your actual user ID):
http://localhost:8080/auth/admin/realms/poc-realm/users/275437d6-a095-
454c-a4d6-4d815a1f8931/groups
o Key: Authorization
o Value: Bearer your-access-token-here (replace with the actual token)
Groups
Group Name Group ID
poc 773fad75-4c5f-4332-a64a-c7a5c7b101c5
test-group 7970d324-dff2-423e-8b2b-f6ad979c84f1
Conclusion
This guide provides the basic operations for interacting with Keycloak’s REST API for user and
group management. For more advanced operations, please refer to the official Keycloak
documentation.
Reference
https://www.keycloak.org/docs-api/latest/rest-api/openapi.json