Skip to main content
Integrate existing identity providers (LDAP, SAML, OIDC) with Keycloak for centralized authentication. See ADR-0037 for architecture details.

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:
  1. External IdP Redirect: User authenticates with their existing identity provider (Azure AD, Okta, Google) using SAML or OIDC
  2. Protocol Response: IdP returns SAML assertion (XML) or OIDC authorization code with ID token
  3. Signature Validation: Keycloak broker validates signatures and assertions against IdP public keys
  4. Claim Extraction: Broker extracts user claims (email, name, roles, groups) from the assertion/token
  5. Attribute Mapping: External claims are mapped to Keycloak user attributes using configured mappers
  6. Token Exchange: External tokens are exchanged for internal Keycloak user representation
  7. Session Creation: Keycloak creates a new user session with federated identity information
  8. Session Storage: Session data is persisted to Redis or database for scalability
  9. JWT Signing: Keycloak generates and signs a new JWT (access + refresh tokens) using its own keys
  10. Client Response: Signed Keycloak JWT is returned to the MCP server for API authentication
Security Considerations:
  • 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

See setup_ldap_federation.py for full documentation.

Google Workspace

See setup_oidc_idp.py for full documentation.

Microsoft 365 / Azure AD

GitHub

Okta

ADFS (SAML)

See setup_saml_idp.py for full documentation.

Authentication Flow

Federated User Login

What Users See

All federated users receive standard Keycloak JWTs:

Configuration Details

LDAP Attribute Mapping

Edit config/ldap_mappers.yaml (reference):

OIDC Provider Configuration

Edit config/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