SSO Integration β developers.healthsafepay.com
Overviewβ
Azure AD (Microsoft Entra ID) SSO using the SPA (client-side) pattern:
- OAuth 2.0 Authorization Code + PKCE flow runs entirely in the browser via
@azure/msal-browser/@azure/msal-react. - This is a static Docusaurus site (no server process) β auth is enforced client-side only.
- SSO is enabled by default (
SSO_ENABLED = trueinsrc/auth/msalConfig.js). The docs are locked behind sign-in ondevelopers.healthsafepay.comonly (isSiteGated()). Onlocalhostthey open without signing in, but MSAL is still available (isSSOEnabled()), so the AI Assistant signs you in the first time you use it.
Identity Provider Registrationβ
These values come from src/auth/msalConfig.js.
| Field | Value |
|---|---|
| Provider | Microsoft Entra ID (Azure AD) |
| Enterprise App | Stage-IAMSSO-OIDC-SS-CCG-Microsite-Internal-app |
| Tenant ID | db05faca-c82a-4b9d-b9c5-0f64b6755421 |
| Client ID | 1da39382-3759-4268-9ede-a9ebfa019abc |
| Client type | Public (SPA) β no client secret in the bundle |
| Authority | https://login.microsoftonline.com/<tenant id> |
| Redirect URI | https://developers.healthsafepay.com/oauth2/callback/ (trailing slash required) |
| Redirect URI (local development) | http://localhost:3000/oauth2/callback/ β register it as a Single-page application redirect URI, with the port you run the dev server on (yarn start defaults to 3000). msalConfig.js sends the current origin plus /oauth2/callback/, so a different port or host needs its own entry. Not verified from this repo: ask the app registration owner to confirm it is configured before relying on local sign-in. |
| Login scopes | openid profile email offline_access api://<client id>/openid |
Current implementationβ
Flow
- The static HTML is pre-rendered, so
plugins/sso-guard.jsinjects a synchronous<head>guard that hides page content and shows "Checking accessβ¦" on protected hosts until auth resolves. src/theme/Root.jswraps the site inMsalProviderand an auth gate. Unauthenticated visitors triggerloginRedirect(loginRequest); authenticated visitors see the site and the guard is removed.- Entra ID redirects back to
/oauth2/callback/, wheresrc/pages/oauth2/callback.jsxinitializes MSAL, callshandleRedirectPromise()and then sends the user to/. On failure it removes the guard and shows a "Login failed" page. - Tokens are cached in
sessionStorage(tab-isolated).
Files
| File | What it does |
|---|---|
src/auth/msalConfig.js | MSAL config (client ID, authority, redirect URI, cache), loginRequest, aiServiceRequest, the SSO_ENABLED flag, isSSOEnabled() (MSAL available: prod and localhost) and isSiteGated() (page gate: prod only) |
src/auth/msalInstance.js | Shared PublicClientApplication singleton (created only when isSSOEnabled()); sets the active account on LOGIN_SUCCESS |
src/theme/Root.js | Swizzled Docusaurus root: MsalProvider, auth gate, login redirect, removes the guard once authenticated |
src/pages/oauth2/callback.jsx | Redirect target; completes the login and handles errors |
plugins/sso-guard.js | Docusaurus plugin (registered in docusaurus.config.js) that prevents a flash of protected content; its PROTECTED_HOSTS must stay in sync with isSiteGated() |
src/components/ChatBot/walletAIService.js | AI Assistant dependency: calls acquireTokenSilent with aiServiceRequest and sends the bearer token on every chat call; falls back to loginRedirect if interaction is required |
ChatBot dependency: aiServiceRequest currently reuses the site's own audience (api://<client id>/openid), so the Assistant backend must validate tokens against that same client ID. See AI Assistant β Overview.
Librariesβ
| Library | Purpose |
|---|---|
@azure/msal-browser | OAuth2 + PKCE engine in the browser |
@azure/msal-react | MsalProvider, AuthenticatedTemplate, UnauthenticatedTemplate, useMsal |
Security Modelβ
Because this is a static site with no backend of its own, there is no server-side token validation for the docs content. Access control is the Entra ID login enforced by the client. The clientId is intentionally public (standard SPA pattern); no secret is involved. Static files themselves are not secret at the network layer, so treat the gate as an access-control layer for internal documentation.
Common Errorsβ
| Error | Cause | Fix |
|---|---|---|
| Blank page after login | handleRedirectPromise() not reached on the callback route | Confirm the redirect URI is exactly /oauth2/callback/ and src/pages/oauth2/callback.jsx is deployed |
redirect_uri mismatch from Entra ID | Registered URI differs from the one in msalConfig.js (e.g. missing trailing slash, or a different port on localhost) | Register https://developers.healthsafepay.com/oauth2/callback/, and for local sign-in http://localhost:<port>/oauth2/callback/ |
AADSTS9002325 | PKCE missing | msal-browser handles PKCE automatically; check for a custom auth call bypassing MSAL |