External Idp Integration Guide
This guide explains how to connect an external identity provider (IdP) to GENIE.AI through Keycloak. Once configured, users can authenticate via the external IdP without any GENIE.AI code or configuration changes.
How It Works
GENIE.AI uses Keycloak as its sole identity boundary. When an external IdP is configured in Keycloak, the authentication flow is:
Browser -> GENIE.AI Frontend -> Keycloak Login Page
|
+-- [Local Credentials] -> Keycloak Token -> GENIE.AI
|
+-- [External IdP Button] -> External IdP Login
|
Keycloak Broker
(issues own token)
|
Keycloak Token -> GENIE.AI
GENIE.AI always receives a standard Keycloak-issued OIDC token, regardless of which external IdP was used. The backend middleware, JIT provisioning, and frontend auth flow are completely unaware of the external IdP.
Prerequisites
- Keycloak admin console access (
https://<your-domain>/auth/admin) - Admin credentials (set via
KEYCLOAK_ADMIN_PASSWORDin.env) - An account with the external IdP provider (Google, Microsoft, etc.)
- Network connectivity from the Keycloak container to the external IdP endpoints
Option 1: Google
Step 1: Create a Google OAuth 2.0 Client
- Go to the Google Cloud Console
- Create a new project or select an existing one
- Navigate to APIs & Services > OAuth consent screen
- Select External user type
- Fill in the required app information (name, support email, developer contact)
- Add test users if in “Testing” mode
- Navigate to APIs & Services > Credentials
- Click Create Credentials > OAuth client ID
- Select Web application as the application type
- Set Authorized redirect URIs to:
Replacehttps://<your-domain>/auth/realms/<realm>/broker/google/endpoint<your-domain>with your public domain (e.g.,gateway.example.com) and<realm>with your Keycloak realm name (default:genie). - Note the Client ID and Client Secret from the credentials page
Step 2: Configure Google in Keycloak
- Open the Keycloak admin console:
https://<your-domain>/auth/admin - Select your realm (e.g.,
genie) - Navigate to Identity Providers in the left menu
- Click Add provider and select Google
- Fill in the configuration:
- Alias:
google(used in URLs, must be unique) - Client ID: The Google OAuth client ID from Step 1
- Client Secret: The Google OAuth client secret from Step 1
- Hosted Domain (optional): Restrict to a specific Google Workspace domain
- Alias:
- Click Save
- (Optional) Navigate to Identity Providers > Google > Mappers to configure claim mapping:
- email: Map Google email to Keycloak email
- first name: Map Google given name to Keycloak first name
- last name: Map Google family name to Keycloak last name
- These mappers are created by default when adding Google
Step 3: Verify
- Navigate to the GENIE.AI login page
- Click Sign in to reach the Keycloak login page
- The Google button should appear below the local credentials form
- Click the Google button and complete the Google sign-in flow
- After successful authentication, you should be redirected back to GENIE.AI
Option 2: Microsoft Entra ID
Step 1: Register an Application in Microsoft Entra ID
- Go to the Microsoft Entra admin center
- Navigate to Applications > App registrations
- Click New registration
- Fill in:
- Name:
GENIE.AI - Keycloak(or any descriptive name) - Supported account types: Select based on your organization’s needs
- Single tenant: Only users in your organization
- Multi-tenant: Users in any organization
- Personal accounts: Microsoft personal accounts (Skype, Xbox, etc.)
- Name:
- Under Redirect URI:
- Select Web platform
- Set the URI to:
https://<your-domain>/auth/realms/<realm>/broker/microsoft/endpoint
- Click Register
- Note the Application (client) ID on the overview page
- Navigate to Certificates & secrets
- Click New client secret
- Note the Value of the client secret (this is shown only once)
Step 2: Configure Microsoft in Keycloak
- Open the Keycloak admin console:
https://<your-domain>/auth/admin - Select your realm (e.g.,
genie) - Navigate to Identity Providers in the left menu
- Click Add provider and select Microsoft
- Fill in the configuration:
- Alias:
microsoft(must be unique) - Client ID: The Application (client) ID from Step 1
- Client Secret: The client secret value from Step 1
- Alias:
- Click Save
- (Optional) Configure mappers under Identity Providers > Microsoft > Mappers:
- email: Map Microsoft email to Keycloak email
- first name: Map Microsoft given name
- last name: Map Microsoft surname
Step 3: Verify
- Navigate to the GENIE.AI login page
- Click Sign in to reach the Keycloak login page
- The Microsoft button should appear below the local credentials form
- Click the Microsoft button and complete the Microsoft sign-in flow
- After successful authentication, you should be redirected back to GENIE.AI
Option 3: Generic OpenID Connect IdP
Any standard-compliant OIDC provider can be connected to Keycloak.
Step 1: Gather IdP Configuration
Obtain the following from your OIDC provider:
- Client ID and Client Secret
- Authorization URL (e.g.,
https://idp.example.com/authorize) - Token URL (e.g.,
https://idp.example.com/token) - User Info URL (e.g.,
https://idp.example.com/userinfo) - Logout URL (optional, e.g.,
https://idp.example.com/logout) - JWKS URL (for token validation, if required)
Many OIDC providers publish these values as a .well-known/openid-configuration JSON document.
Step 2: Configure the OIDC IdP in Keycloak
- Open the Keycloak admin console:
https://<your-domain>/auth/admin - Select your realm (e.g.,
genie) - Navigate to Identity Providers in the left menu
- Click Add provider and select OpenID Connect v1.0
- Fill in the configuration:
- Alias: A unique identifier (e.g.,
my-idp) - Display Name: A human-readable name shown on the login page
- Authorization URL: The provider’s authorization endpoint
- Token URL: The provider’s token endpoint
- Client ID: Your client identifier at the IdP
- Client Secret: Your client secret at the IdP
- Client Authentication: Set to Client secret sent as post (or match your IdP’s requirements)
- User Info URL: The provider’s userinfo endpoint
- Default Scopes:
openid email profile(adjust based on what the IdP supports)
- Alias: A unique identifier (e.g.,
- Click Save
Step 3: Configure Redirect URI at the External IdP
Set the redirect URI at your external IdP to:
https://<your-domain>/auth/realms/<realm>/broker/<alias>/endpoint
Replace <alias> with the alias you chose in Step 2 (e.g., my-idp).
Step 4: Configure Claim Mappers
Navigate to Identity Providers >
| Mapper Type | External Claim | Keycloak Attribute |
|---|---|---|
| Attribute Importer | email | email |
| Attribute Importer | given_name | firstName |
| Attribute Importer | family_name | lastName |
Step 5: Verify
- Navigate to the GENIE.AI login page
- Click Sign in to reach the Keycloak login page
- The IdP button (with your display name) should appear on the login page
- Click the button and complete the external IdP sign-in flow
- After successful authentication, you should be redirected back to GENIE.AI
Option 4: SAML Identity Providers
Keycloak also supports SAML 2.0 identity providers (e.g., Shibboleth, Active Directory Federation Services, institutional SAML IdPs). The configuration flow is similar to OIDC but uses different fields.
Step 1: Gather SAML IdP Configuration
Obtain the following from your SAML IdP administrator:
- Entity ID (the IdP’s unique identifier)
- SSO Service URL (where Keycloak redirects users for login)
- SLO Service URL (optional, for single logout)
- Signing Certificate (X.509 certificate to validate IdP responses)
Many SAML IdPs provide these as a metadata XML file.
Step 2: Configure SAML in Keycloak
- Open the Keycloak admin console:
https://<your-domain>/auth/admin - Select your realm (e.g.,
genie) - Navigate to Identity Providers in the left menu
- Click Add provider and select SAML v2.0
- Fill in the configuration:
- Alias: A unique identifier (e.g.,
institutional-idp) - Display Name: A human-readable name shown on the login page
- SAML Entity ID: The provider’s entity ID
- Single Sign-On Service URL: The provider’s SSO endpoint
- You can also paste the SAML Metadata URL or upload the Metadata XML file, which auto-fills most fields
- Alias: A unique identifier (e.g.,
- Click Save
Step 3: Configure Redirect URI
Set the relying party / service provider assertion consumer service (ACS) URL at the SAML IdP to:
https://<your-domain>/auth/realms/<realm>/broker/<alias>/endpoint
SAML IdPs may also need the Entity ID of Keycloak’s broker endpoint:
https://<your-domain>/auth/realms/<realm>
Step 4: Verify
Follow the same verification steps as for OIDC providers (navigate to login page, click the IdP button, complete the flow).
Optional: Automated IdP Configuration via keycloak-config-cli
Instead of using the Keycloak admin console, you can define identity providers in configs/keycloak/genie-realm.yaml for automated provisioning.
Example: Adding Google via YAML
Add the following section to genie-realm.yaml:
identityProviders:
- alias: google
providerId: google
enabled: true
config:
clientId: $(env:KEYCLOAK_GOOGLE_CLIENT_ID)
clientSecret: $(env:KEYCLOAK_GOOGLE_CLIENT_SECRET)
mappers:
- name: google-email
identityProviderAlias: google
identityProviderMapper: oidc-user-attribute-idp-mapper
config:
claim: email
userAttribute: email
- name: google-first-name
identityProviderAlias: google
identityProviderMapper: oidc-user-attribute-idp-mapper
config:
claim: given_name
userAttribute: firstName
- name: google-last-name
identityProviderAlias: google
identityProviderMapper: oidc-user-attribute-idp-mapper
config:
claim: family_name
userAttribute: lastName
Then inject the secrets via environment variables in the Keycloak config service:
# In docker-compose.yaml, under keycloak-config environment:
- KEYCLOAK_GOOGLE_CLIENT_ID=${KEYCLOAK_GOOGLE_CLIENT_ID}
- KEYCLOAK_GOOGLE_CLIENT_SECRET=${KEYCLOAK_GOOGLE_CLIENT_SECRET}
And add the variables to your .env file:
KEYCLOAK_GOOGLE_CLIENT_ID=<google-oauth-client-id>
KEYCLOAK_GOOGLE_CLIENT_SECRET=<google-oauth-client-secret>
Note: This approach is optional. The Keycloak admin console method is recommended for most deployments. The choice of method is an administrative decision and does not affect GENIE.AI in any way. Be aware that adding identity providers to genie-realm.yaml modifies a version-controlled file — changes will be tracked in git and applied on every deployment. The admin console approach stores configuration in Keycloak’s database instead.
What Happens After Authentication
When a user authenticates via an external IdP:
- The user clicks the external IdP button on Keycloak’s login page
- Keycloak redirects to the external IdP’s authorization endpoint
- The user authenticates and authorizes the application at the external IdP
- The external IdP redirects back to Keycloak’s broker callback endpoint
- Keycloak exchanges the external token for a Keycloak session
- Keycloak issues its own standard OIDC token to GENIE.AI
- GENIE.AI’s frontend receives the token via the standard
/api/auth/callbackflow - The backend validates the Keycloak token via JWKS, completely unaware of the external IdP
- JIT provisioning creates or updates the user in ArangoDB using the Keycloak token claims
Important Notes
Network Requirements
- The Keycloak container must be able to reach the external IdP’s authorization, token, and userinfo endpoints
- NGINX does not proxy external IdP traffic; Keycloak makes direct outbound connections
- If your deployment uses a corporate proxy, configure the
HTTP_PROXYandHTTPS_PROXYenvironment variables on the Keycloak service
Air-Gapped Deployments
External identity providers are not available in air-gapped deployments (no internet connectivity). Only local Keycloak credentials work in air-gapped environments. See the deployment guide for air-gapped details.
Role and Attribute Mapping
This guide covers basic authentication only. Advanced role and attribute mapping from external IdP attributes to Keycloak roles is not covered in this guide. By default, externally-authenticated users receive the default realm roles configured in Keycloak.
First Login Flow
On first login via an external IdP, Keycloak may prompt the user to confirm their account details (email, name). This behavior can be configured in the Keycloak realm settings under Authentication > First Login Flow.
Disabling an External IdP
To temporarily disable an external IdP without removing its configuration:
- Open the Keycloak admin console
- Navigate to Identity Providers
- Select the provider and toggle Enabled to Off
Users will no longer see the IdP button on the login page, but the configuration is preserved for re-enabling later.
Account Linking
When a user first registers with local Keycloak credentials and later logs in via an external IdP (same email address), Keycloak creates a separate account. GENIE.AI’s JIT provisioning uses the {iss}#{sub} composite key — the sub from Keycloak differs between local and brokered accounts, resulting in two distinct ArangoDB user records.
To link accounts, use the Keycloak admin console: Users > [select user] > Identity Provider Links > Link account. This is an administrative action and does not affect GENIE.AI code.
Troubleshooting
“Invalid redirect URI” error at the external IdP
The redirect URI configured at the external IdP must exactly match Keycloak’s broker endpoint:
https://<your-domain>/auth/realms/<realm>/broker/<alias>/endpoint
Common mistakes:
- Missing
/authprefix (NGINX routes/authto Keycloak) - Wrong realm name
- Wrong alias
- HTTP instead of HTTPS
External IdP button does not appear on login page
- Verify the identity provider is enabled in Keycloak
- Verify the provider is configured in the correct realm
- Check Keycloak logs for errors:
docker service logs genieai_keycloak --tail 50
User not created in ArangoDB after external IdP login
- Verify the JIT provisioning service is running:
docker service logs genieai_backend --tail 50 - Check that the Keycloak token contains the expected claims (
email,sub,iss) - Verify the
subclaim in the Keycloak token is Keycloak’s internal user ID (not the external IdP’s)
Network connectivity issues
From the Keycloak container, test connectivity to the external IdP:
docker exec -it $(docker ps --filter "name=genieai_keycloak" -q | head -1) bash
curl -v https://accounts.google.com/.well-known/openid-configuration
If this fails, check network/firewall rules between the Keycloak container and the external IdP.