Integrate GL IAM with Keycloak for enterprise-grade identity management.
When to use Keycloak: Choose Keycloak for enterprise environments with existing Keycloak infrastructure, advanced identity features (SSO, MFA, federation), or requirements for OIDC/SAML protocol support.
What you'll build: A FastAPI application that authenticates users via Keycloak tokens and enforces role-based access control using GL IAM's unified interface.
Prerequisites
This example requires completion of all setup steps listed on the Prerequisites page. To summarize:
Python 3.11+
Docker and Docker Compose
Access to the GDP Labs' Gen AI SDK repository (request via form or ticket@gdplabs.id)
The pre-configured realm includes these test users:
Email
Password
Roles
user@example.com
user123
member
admin@example.com
admin123
admin, member
Installation
Install GL IAM from the internal Google Artifact Registry (latest version).
5-Line Core
The essential code to validate Keycloak tokens with GL IAM:
Step-by-Step
1
Configure Environment
Create .env file:
2
Setup Provider
3
Add Protected Endpoints
4
Run the Server
Output:
5
Test the API
Get a token using the Resource Owner Password Grant:
6
Test Admin Access
Congratulations! You've integrated GL IAM with Keycloak.
Complete Example
Create main.py:
Run it:
Keycloak Role Mapping
Keycloak realm roles map to GL IAM standard roles:
Keycloak Role
GL IAM Standard Role
Access Level
admin
ORG_ADMIN
Admin endpoints
member
ORG_MEMBER
Member endpoints
Common Pitfalls
Pitfall
Solution
Keycloak not starting
Wait 30-60 seconds on first start; check docker-compose logs keycloak
Token validation fails
Ensure client_secret matches the Keycloak client configuration
User has no roles
Assign realm roles to the user in Keycloak admin console
Port 8080 in use
Change the port mapping in docker-compose.yml
Resource Owner Password Grant disabled
Enable "Direct Access Grants" on the Keycloak client
Cleanup
Stop and remove the Keycloak container:
Production Notes
The Resource Owner Password Grant used in this quickstart is for testing only. In production, use the Authorization Code Flow with PKCE for better security.
For production deployments:
Use HTTPS for the Keycloak server URL
Configure proper SSL/TLS certificates
Set up realm roles and client scopes according to your security requirements
Consider using Keycloak's built-in user federation for LDAP/Active Directory integration