Checking access…

Skip to main content

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 = true in src/auth/msalConfig.js). The docs are locked behind sign-in on developers.healthsafepay.com only (isSiteGated()). On localhost they 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.

FieldValue
ProviderMicrosoft Entra ID (Azure AD)
Enterprise AppStage-IAMSSO-OIDC-SS-CCG-Microsite-Internal-app
Tenant IDdb05faca-c82a-4b9d-b9c5-0f64b6755421
Client ID1da39382-3759-4268-9ede-a9ebfa019abc
Client typePublic (SPA) β€” no client secret in the bundle
Authorityhttps://login.microsoftonline.com/<tenant id>
Redirect URIhttps://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 scopesopenid profile email offline_access api://<client id>/openid

Current implementation​

Flow

  1. The static HTML is pre-rendered, so plugins/sso-guard.js injects a synchronous <head> guard that hides page content and shows "Checking access…" on protected hosts until auth resolves.
  2. src/theme/Root.js wraps the site in MsalProvider and an auth gate. Unauthenticated visitors trigger loginRedirect(loginRequest); authenticated visitors see the site and the guard is removed.
  3. Entra ID redirects back to /oauth2/callback/, where src/pages/oauth2/callback.jsx initializes MSAL, calls handleRedirectPromise() and then sends the user to /. On failure it removes the guard and shows a "Login failed" page.
  4. Tokens are cached in sessionStorage (tab-isolated).

Files

FileWhat it does
src/auth/msalConfig.jsMSAL 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.jsShared PublicClientApplication singleton (created only when isSSOEnabled()); sets the active account on LOGIN_SUCCESS
src/theme/Root.jsSwizzled Docusaurus root: MsalProvider, auth gate, login redirect, removes the guard once authenticated
src/pages/oauth2/callback.jsxRedirect target; completes the login and handles errors
plugins/sso-guard.jsDocusaurus 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.jsAI 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​

LibraryPurpose
@azure/msal-browserOAuth2 + PKCE engine in the browser
@azure/msal-reactMsalProvider, 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​

ErrorCauseFix
Blank page after loginhandleRedirectPromise() not reached on the callback routeConfirm the redirect URI is exactly /oauth2/callback/ and src/pages/oauth2/callback.jsx is deployed
redirect_uri mismatch from Entra IDRegistered 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/
AADSTS9002325PKCE missingmsal-browser handles PKCE automatically; check for a custom auth call bypassing MSAL