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
1
OIDC Discovery
The client discovers the realm’s OpenID configuration at:
2
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.
3
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.
4
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
5
API Requests
All API requests include the access token in the
Authorization: Bearer header. The platform validates the token and extracts the organization context from the realm.JWT Token Structure
The access token contains standard OIDC claims plus platform-specific claims: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.SSO Integration
Each Keycloak realm can be configured with external identity providers for single sign-on:
Since each organization is a separate realm, SSO configuration is fully tenant-isolated. One organization can use SAML with Okta while another uses LDAP with Active Directory.
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.

