Skip to content

ADR-005: Keycloak as Authentication Provider

Date: 2026-02-27 Authors: Jean-Francois Meyers Scope: @granit/authentication, @granit/react-authentication, @granit/react-authorization

The platform operates in a healthcare data hosting (HDS) context that imposes strict authentication requirements:

  • OpenID Connect / OAuth 2.0: standard protocols required
  • Complete audit: connection and session traceability
  • Multi-tenant: realm isolation per tenant
  • HDS compliance: the provider must be hostable in France on private infrastructure (no US cloud)
  • Open source: no commercial lock-in

Use Keycloak as the authentication provider via the following packages:

  • @granit/authentication — OIDC types (framework-agnostic)
  • @granit/react-authentication — Keycloak init hook, auth context factory, mock provider
  • @granit/react-authorization — Permission checking hooks (RBAC)

The packages encapsulate keycloak-js and expose:

  • A React authentication context (BaseAuthContextType)
  • Integration hooks (useAuth, useKeycloakInit, usePermissions)
  • A mock provider for tests and local development
  • A 401 interceptor for revoked session handling

The BaseAuthContextType is an extensible interface: consumer applications add their own fields (e.g. register, hasAdminRole).

  • Advantage: open source (Apache 2.0), self-hosted, standard protocols, CNCF project, large community, realm-per-tenant isolation
  • Disadvantage: operational burden (deployment, updates, realm backup, monitoring), keycloak-js API sometimes unstable between major versions
  • Advantage: fully managed SaaS, excellent developer experience
  • Disadvantage: incompatible with HDS — hosted in the US, Cloud Act applies, commercial lock-in
  • Advantage: native Azure integration, managed service
  • Disadvantage: Azure dependency, US Cloud Act applies, complex configuration for custom flows
  • Advantage: full control, no external dependency
  • Disadvantage: enormous implementation effort, security risk, no community review, certification burden
CriterionKeycloakAuth0Azure AD B2CCustom
HDS complianceYes (self-hosted EU)No (US)No (US Cloud Act)Yes
Open sourceYes (Apache 2.0)NoNoYes
OIDC/OAuth 2.0NativeNativeNativeManual
Multi-tenant (realms)NativePer-tenant plansPartialManual
Operational costSelf-hostedSaaS feeAzure feeDevelopment cost
CommunityCNCF, Red HatLargeLargeNone
PackageRole
keycloak-jsOfficial Keycloak JavaScript adapter
  • HDS compliance: Keycloak is self-hosted on private European infrastructure
  • Standards: OpenID Connect, OAuth 2.0, SAML 2.0 supported natively
  • Extensibility: themes, SPIs, identity federation
  • Community: CNCF project, active Red Hat maintenance
  • Isolation: one realm per tenant, no shared data
  • Operations: Keycloak must be deployed and maintained (updates, realm backup, monitoring)
  • Complexity: realm, client, and role configuration is non-trivial
  • keycloak-js: the official client library has occasionally unstable APIs between major versions

This decision should be re-evaluated if:

  • A European managed identity service emerges with HDS certification
  • Keycloak maintenance burden becomes disproportionate
  • keycloak-js is deprecated in favor of a generic OIDC client