Identity Federation Protocol Flow
The following diagram shows the detailed protocol flow for federating external identity providers (Azure AD, Okta, Google) through Keycloak, including SAML/OIDC exchanges, token handling, and JWT issuance: Key Steps in the Federation Flow:- External IdP Redirect: User authenticates with their existing identity provider (Azure AD, Okta, Google) using SAML or OIDC
- Protocol Response: IdP returns SAML assertion (XML) or OIDC authorization code with ID token
- Signature Validation: Keycloak broker validates signatures and assertions against IdP public keys
- Claim Extraction: Broker extracts user claims (email, name, roles, groups) from the assertion/token
- Attribute Mapping: External claims are mapped to Keycloak user attributes using configured mappers
- Token Exchange: External tokens are exchanged for internal Keycloak user representation
- Session Creation: Keycloak creates a new user session with federated identity information
- Session Storage: Session data is persisted to Redis or database for scalability
- JWT Signing: Keycloak generates and signs a new JWT (access + refresh tokens) using its own keys
- Client Response: Signed Keycloak JWT is returned to the MCP server for API authentication
- Signature Verification: All external tokens/assertions are cryptographically verified
- Token Exchange: External tokens are never passed directly to clients - always exchanged for Keycloak JWTs
- Session Isolation: Federated sessions are isolated from local Keycloak sessions
- Attribute Validation: Mapped attributes are validated against Keycloak schema
- Replay Protection: SAML assertions include timestamp and ID validation to prevent replay attacks
Quick Setup
LDAP/Active Directory
Google Workspace
Microsoft 365 / Azure AD
GitHub
Okta
ADFS (SAML)
Authentication Flow
Federated User Login
What Users See
All federated users receive standard Keycloak JWTs:Configuration Details
LDAP Attribute Mapping
Editconfig/ldap_mappers.yaml (reference):
OIDC Provider Configuration
Editconfig/oidc_providers.yaml (reference):
Testing
Test LDAP Connection
Test OIDC Login
Verify JWT Issuance
Troubleshooting
LDAP Connection Failed
Check:- LDAP URL is accessible from Keycloak pod
- Bind DN and password are correct
- Users DN exists
- Firewall allows LDAP traffic (port 389/636)
SAML Metadata Import Failed
Solutions:- Download SAML metadata from IdP
- Import manually in Keycloak Admin Console
- Verify SAML signature algorithm matches (RSA-SHA256)
OIDC Provider Not Found
Check:- Client ID and secret are correct
- Redirect URI is configured in external IdP
- Scopes are correct (openid profile email)
References
- ADR: ADR-0037: Identity Federation
- LDAP Setup:
scripts/setup/setup_ldap_federation.py - SAML Setup:
scripts/setup/setup_saml_idp.py - OIDC Setup:
scripts/setup/setup_oidc_idp.py - Configuration:
config/ldap_mappers.yaml,config/oidc_providers.yaml