Azure Entra

Microsoft Azure AD / Entra ID integration for Single Sign-On (SSO). Allows users to authenticate with their Microsoft organizational account instead of email/password.

Architecture

ComponentPath
Auth routebackend/src/routes/entra-auth.ts
Servicebackend/src/services/entra/
Frontend callbackfrontend/src/pages/AuthCallback.tsx

SSO Flow

  1. User clicks “Sign in with Microsoft” on login page
  2. Frontend redirects to Azure Entra authorization endpoint
  3. User authenticates with Microsoft credentials
  4. Azure redirects back to /auth/callback with authorization code
  5. Backend exchanges code for tokens, extracts user identity
  6. Creates or links Users account, issues JWT session
  7. Frontend AuthCallback page stores JWT and redirects to app

Redirect URI Management

Each environment needs its redirect URI registered in Azure Entra:

EnvironmentURI Pattern
Developmenthttp://localhost:<port>/auth/callback
Staginghttps://staging.renewa.app/auth/callback
Productionhttps://app.renewa.app/auth/callback
PR Previewhttps://renewa-app-pr-<N>.fly.dev/auth/callback

Managed via: make sso-register which runs scripts/manage-entra-redirect-uri.sh.

See PR Preview Deployments for preview URI registration, Makefile Commands for SSO commands.

Configuration

SecretPurpose
Azure Tenant IDOrganization directory
Azure Client IDApp registration identifier
Azure Client SecretApp authentication

Stored as GitHub Environment Secrets, synced to Fly.io. See Deployment Pipeline.

User Provisioning

On first SSO login, the system:

  1. Checks if a Users account exists with the Microsoft email
  2. If exists: links the Azure identity and logs in
  3. If not: creates a new user account from the Azure profile