Skip to main content

๐Ÿ” OIDC SSO Setup Guide (Azure AD / Entra ID)

This guide walks through the complete setup of Single Sign-On (SSO) for X-AutoMate using Microsoft Entra ID (Azure AD) as the Identity Provider (IdP) via OpenID Connect (OIDC).

Throughout this guide, <your-backend-url> is the public URL of your X-AutoMate backend (for example https://devxautomate.bos.no) and <your-frontend-url> is the public URL users open in the browser. Always use the real deployment URLs โ€” never localhost.

โ˜๏ธ 1. Azure AD App Registrationโ€‹

  1. Go to Azure Portal โ†’ Microsoft Entra ID โ†’ Add โ†’ App Registration โ†’ New Registration.

  2. Configure:

    • Name: x-automate (or x-automate-dev)
    • Supported account types: Single Tenant (or Multi-Tenant)
    • Redirect URI:
      • Platform: Web
      • URI: https://<your-backend-url>/main/api_v2/login/sso/callback
    Include the /main prefix

    The backend API is served under the /main base path. A redirect URI without it (https://<your-backend-url>/api_v2/login/sso/callback) will not work โ€” Azure will redirect to a path that does not exist and the login will fail.

  3. Save:

    • ๐Ÿ†” Client ID
    • ๐Ÿข Tenant ID
  4. Create a Client Secret under Manage โ†’ Certificates & Secrets (we'll need Secret ID value for AZURE_AD_CLIENT_SECRET env).

๐ŸŽซ Enable ID Tokensโ€‹

Enable ID Tokens under Manage โ†’ Authentication โ†’ Settings โ†’ Implicit Grant and Hybrid Flows.

๐Ÿ‘ฅ 2. App Roles Setupโ€‹

On Manage โ†’ App roles โ†’ Create app role

Display name, Value, Description Role values follow:

{project}_{role} (lower case project name and role with underscore separation)

Available roles:

  • admin
  • tester
  • dq_admin
  • dq_tester
  • test_admin

Examples:

  • default_admin
  • default_tester
  • default_dq_admin
  • default_dq_tester
  • default_test_admin
  • myproject_tester etc

For Allowed member types field select Both (Users/Groups + Applications)

Role names must match X-AutoMate exactly

The {role} part of the Azure app role value is matched against the project role name in X-AutoMate exactly, and the comparison is case-sensitive. Use the same spelling and the same case on both sides:

  • Azure value default_admin โ†’ project default, role admin โ†’ X-AutoMate must have an OIDC project role named exactly admin โ€” not Admin, and not a synonym such as administrator.

See ProjectRole Mapping for how to create the matching roles.

๐Ÿ‘ค Assign Usersโ€‹

On Enterprise Applications:

  • Manage โ†’ All applications
  • Select the app you created at App registration step
  • Manage โ†’ Users and Groups โ†’ Add User/Group โ†’ Assign App Roles (select user and assign role)
Email addresses must match

The email address of the X-AutoMate user must be identical to the email address of the account in Entra ID. Users are matched by email when they log in through SSO, so a mismatch (a different domain, an alias, or a typo) means the login will not resolve to the expected user.

โš™๏ธ 3. Environment Variablesโ€‹

SSO_ENABLED=True
AZURE_AD_TENANT_ID=<tenant-id>
AZURE_AD_CLIENT_ID=<client-id>
AZURE_AD_CLIENT_SECRET=<client-secret>
AZURE_AD_REDIRECT_URI=https://<your-backend-url>/main/api_v2/login/sso/callback
AZURE_AD_AUTHORITY=https://login.microsoftonline.com
FRONTEND_BASE_URL=https://<your-frontend-url>

AZURE_AD_REDIRECT_URI must be the backend URL of the deployment you are configuring and must be identical to the redirect URI registered in Azure (step 1), including the /main prefix.

FRONTEND_BASE_URL is where the backend sends the browser back to after the SSO callback, including when the login fails. If it is not set it falls back to localhost, so a failed login redirects to an address the user's browser cannot reach โ€” the login appears to end in a bare 302 with no indication of what went wrong. Always set it explicitly.

๐Ÿงฉ Role Claim Patternโ€‹

Default:

^(?P<project>[^_]+)_(?P<role>.+)$

๐Ÿ—„๏ธ 4. ProjectRole Mappingโ€‹

Every Azure App Role must have a matching ProjectRole entry with source OIDC.

OIDC roles are not created automatically

A newly created project โ€” including the default project โ€” has no OIDC project roles. Until an administrator creates them, every SSO login fails because the role from Azure has nothing to match against in the project. Create the OIDC roles before the first SSO login.

Create one entry per Azure app role, using the {role} part of the Azure value verbatim (lower case, exactly as it appears in Azure):

{
"project_role_name":"admin",
"project_role_source":"OIDC"
}

So an Azure app role with value default_admin requires the project default to have an OIDC project role named admin. Because the match is case-sensitive, a role named Admin or administrator will not match default_admin.

๐Ÿ”„ 5. SSO Login Flowโ€‹

  1. Frontend calls /api_v2/login/sso/authorize
  2. User authenticates with Azure AD
  3. Azure redirects to callback
  4. Backend validates token
  5. User is auto-provisioned
  6. Roles are synchronized
  7. ID token is returned

๐Ÿงช SSO Test Pageโ€‹

Available at:

https://<your-backend-url>/sso-test

Features:

  • ๐Ÿ”‘ Login testing
  • ๐Ÿ‘€ View claims
  • ๐Ÿงฉ View parsed roles
  • ๐Ÿ› ๏ธ API testing

๐Ÿšจ Troubleshootingโ€‹

โŒ SSO is not enabledโ€‹

Verify:

SSO_ENABLED=True

โŒ Login ends in a 302 with no error messageโ€‹

FRONTEND_BASE_URL is not set, so the backend redirects errors to localhost instead of your frontend. Set it to your frontend URL and retry โ€” the actual error will then be shown:

FRONTEND_BASE_URL=https://<your-frontend-url>

โŒ Signature verification failedโ€‹

Use the id_token instead of access_token.

โŒ Redirect fails after authenticating with Azureโ€‹

Verify the redirect URI includes the /main prefix and is identical in Azure and in AZURE_AD_REDIRECT_URI:

https://<your-backend-url>/main/api_v2/login/sso/callback

โŒ A user with this email already existsโ€‹

The email address returned by Entra ID already belongs to a local (username/password) X-AutoMate account, and SSO does not currently link an existing local account to an SSO identity. Either remove the local account before the first SSO login, or use a different email address for the SSO user.

โŒ User has no project accessโ€‹

Verify:

  • Azure App Role assignment
  • Matching ProjectRole entry exists in the project with source OIDC (these are not created by default โ€” see ProjectRole Mapping)
  • The role name matches the Azure value exactly, including case (default_admin โ†’ admin)
  • The user's email in X-AutoMate matches the email in Entra ID
  • Correct claim pattern

โŒ Roles not appearingโ€‹

Verify:

  • App Roles exist
  • App Roles are enabled
  • User is assigned to the role