Documentation Index
Fetch the complete documentation index at: https://docs.emergence.ai/llms.txt
Use this file to discover all available pages before exploring further.
Authentication
CRAFT uses Keycloak as its identity provider, configured in a multi-realm architecture where each organization is a separate Keycloak realm. Authentication follows the OpenID Connect (OIDC) protocol with PKCE (Proof Key for Code Exchange) for browser-based clients.Keycloak is self-hosted — the platform’s identity layer runs on your infrastructure and does not depend on a cloud-native identity service. You can federate external enterprise identity providers (Entra ID, Okta, Google Workspace) through standard OIDC and SAML protocols.
Multi-Realm Architecture
Each organization maps to a dedicated Keycloak realm:- Users in one realm cannot see or access users in another
- Each realm has independent password policies, session settings, and identity providers
- Group memberships are realm-scoped and appear as JWT claims
- SSO can be configured per-realm (e.g., SAML, LDAP, social login)
Authentication Flow
Authorization Request (PKCE)
The browser initiates the OIDC authorization code flow with PKCE. A code verifier is generated client-side and the SHA-256 code challenge is sent with the authorization request. No client secret is required.
User Login
The user authenticates at the Keycloak login page for their realm. Keycloak supports username/password, SSO via external IdPs (SAML, OIDC federation), LDAP, and social login.
Token Exchange
After successful login, Keycloak returns an authorization code. The client exchanges it (with the code verifier) for:
- Access token (JWT) — Used for API authorization
- Refresh token — Used to obtain new access tokens
- ID token — Contains user identity claims
JWT Token Structure
The access token contains standard OIDC claims plus platform-specific claims:| Claim | Purpose |
|---|---|
sub | User ID for OpenFGA permission checks |
iss | Realm extraction — the path segment after /realms/ becomes org_id |
groups | Keycloak group memberships, used for group-based OpenFGA permission checks |
azp | Client ID of the application that requested the token |
exp / iat | Token expiration and issuance timestamps |
Token Validation
The Governance service validates tokens using a multi-step process:- Validation Steps
- Security Properties
- Extract realm — The token’s
issclaim is decoded (without verification) to determine the Keycloak realm - Fetch JWKS — Public keys are fetched from the realm’s JWKS endpoint (cached per realm via
lru_cache) - Verify signature — The token signature is validated against the realm’s public key, which cryptographically proves the token was issued by the platform’s Keycloak instance
- Check expiration — Standard JWT expiration (
exp) validation - Verify issuer consistency — The issuer from the verified token must match the initial unverified extraction
- Extract claims —
org_id, groups, roles, and user identity are extracted into theAuthobject
Service Accounts
Service accounts are used by background workers and automated processes that need to access the platform without user interaction. They are identified by a three-check detection. See Service Accounts for a complete guide including token management, creation steps, and code examples.1. Master Realm Authentication
1. Master Realm Authentication
Service accounts authenticate via the Keycloak
master realm, not an organization realm. Their org_id is null by default.2. Client ID Convention
2. Client ID Convention
Service account client IDs must start with the
svc- prefix (e.g., svc-data-readiness, svc-talk2data). This is a naming convention enforced by the detection logic.3. Role Membership
3. Role Membership
Service accounts must have the
serviceAccount role in realm_access.roles. This provides defense in depth — even if someone creates a client with a svc- prefix, it will not be treated as a service account without the role.| Header | Purpose | Required |
|---|---|---|
X-Org-Id | Specifies the organization context (since master realm tokens have no org) | Yes |
X-On-Behalf-Of | Identifies the original user in audit logs when acting on their behalf | Optional |
SSO Integration
Each Keycloak realm can be configured with external identity providers for single sign-on:| Provider Type | Configuration |
|---|---|
| SAML 2.0 | Enterprise IdP integration (Okta, Azure AD, PingFederate) |
| OIDC Federation | Connect to another OIDC provider |
| LDAP/AD | Sync users from Active Directory or LDAP |
| Social Login | Google, GitHub, Microsoft (per-realm configuration) |
Obtaining Tokens
- Development
- Platform Admin
- Programmatic (OIDC)
Next Steps
Authorization
Learn how JWT claims are used for OpenFGA permission checks.
Organizations
Understand how organizations map to Keycloak realms.
Multi-Tenancy
See the full tenant isolation architecture.
Projects
Learn how the X-Project-ID header provides project context.

