Skip to content

Keycloak Identity Platform

Microtec ERP uses a customized Keycloak 26.2.4 instance as the central identity and access management platform. It is extended with 7 proprietary Java SPI extensions to support multi-tenant ERP workflows, Google-style account switching, and automated realm provisioning.


Deployment

Keycloak runs as a containerized workload inside the Public Container Apps Environment (CAE), alongside the API Gateway. It is internet-facing with HTTPS ingress and handles all authentication flows for ERP and Business Owner portals.


Realm Architecture

Keycloak hosts two separate realms to isolate ERP tenant users from Business Owner portal administrators.

RealmPurposeApps
microtecERP tenant usersAll 9 MFE apps (accounting, HR, finance, sales, purchase, inventory, distribution, fixed-assets, erp-home)
businessownerBO portal adminsbussiness-owners app (port 4301)

Why Two Realms?

Separating realms enforces complete isolation of user pools, token policies, and session management between tenant users and platform administrators. A Business Owner admin cannot inadvertently access ERP user sessions and vice versa.


Custom SPI Extensions

Seven Java SPI (Service Provider Interface) extensions are deployed as JAR files into Keycloak's providers/ directory:

#ExtensionTypePurpose
1keycloak-multiaccountAuthenticator + RESTGoogle-style tenant switching without logout
2keycloak-seedingEventListener + RESTAuto-provision realms/clients/roles on startup
3phone-email-authenticatorAuthenticatorLogin via phone number or email
4tenant-mapperProtocol MapperInject tenant context into JWT claims
5role-syncEventListenerSync Keycloak roles to ERP permission tables
6audit-event-listenerEventListenerEmit auth events to Azure Service Bus
7custom-theme-providerThemeRTL-aware Arabic/English UI themes

Authentication Flow Priority

The default browser authentication flow for the microtec realm uses three sequential execution steps. Priority determines the order in which each authenticator is attempted:

StepAuthenticatorPriorityDescription
1MAC (Multi-Account Cookie)10Checks AES-256-GCM encrypted cookie for active account session
2Cookie20Standard Keycloak browser session cookie check
3Identity Provider Redirector30Redirects to configured external IdP (Azure AD, Google, etc.)

Priority Order is Critical

MAC must run at priority 10 (before standard Cookie at 20). If Cookie runs first, it intercepts multi-tenant sessions before the account switcher can activate the correct tenant context. This was a known production bug fixed in Session 16.


Custom Authentication Flow: phone-email-authenticator

The phone-email-authenticator flow replaces the standard username/password form to allow login with either an email address or a phone number:


Environment-Specific Configuration

Config KeyValue
Keycloak version26.2.4
Container imageCustom build with SPIs bundled
CAE typePublic (internet-facing ingress)
Min replicas1
Max replicas3
CPU1.0 vCPU
Memory2Gi
Health probe path/health/ready (port 9000)
Admin consoleDisabled in production

Internal Documentation — Microtec Platform Team