Auth0 Enterprise Group Roles Missing From Tokens After Entra ID SCIM Provisioning

Overview

When Microsoft Entra ID provisions enterprise groups to Auth0 via System for Cross-domain Identity Management (SCIM), the assigned roles fail to appear in the token during application login. This issue occurs when the SCIM mapping creates duplicate or incompatible user IDs, and because the default Auth0 authorization event object only includes directly assigned roles. Correct the SCIM mapping on both the Auth0 connection and Microsoft Entra ID, and implement a Post-Login Action using the native Auth0 api.roles method to retrieve and append effective roles to the token.

Applies To

  • Auth0
  • Enterprise Connections
  • Microsoft Entra ID
  • SCIM
  • Auth0 Actions

Cause

The enterprise connection lacks the correct SCIM configuration for the external identifier on both the Auth0 and Microsoft Entra ID sides. This misconfiguration causes Auth0 to create duplicate users. Additionally, the default event.authorization.roles property only contains directly assigned roles. Auth0 does not automatically inject effective enterprise group roles into tokens without a custom Post-Login Action.

Solution

What steps update the Auth0 SCIM connection settings?

Update the Auth0 SCIM connection settings to use the correct identifier type and endpoints for Microsoft Entra ID SCIM provisioning.

  1. Open the Auth0 Dashboard and navigate to the specific Microsoft Entra ID Enterprise Connection.
  2. Set the User ID Attribute Type to User Object Identifier (oid).
  3. Clear Use Common Endpoint.
  4. Navigate to the Mapping tab within the connection and confirm that the SCIM attribute containing the User ID is set to externalId.

 

Correct the Microsoft Entra ID SCIM Mapping

Update the provisioning mappings in the Microsoft Entra admin center to ensure Auth0 links the provisioned users correctly.

  1. Open the Microsoft Entra admin center.
  2. Navigate to Provisioning > Edit Provisioning > Mappings.
  3. Select Provision Microsoft Entra ID Users.
  4. Locate the row for the externalId attribute.
  5. Configure the mapping type as Direct.
  6. Set the source attribute to objectId.
  7. Set the target attribute to externalId.

 

What steps add effective group roles to the token using an Action?

Create a Post-Login Action in the Auth0 Dashboard to retrieve a user's effective roles and append them as custom claims. If the login is within an organization context, the effective-roles call returns organization-scoped roles.

  1. Go to the Auth0 Dashboard.
  2. Navigate to Actions > Library and select Build Custom.
  3. Enter a name for the Action, choose Login / Post Login for the trigger, and select the recommended Node.js version.
  4. Enter the following code into the editor: 
    exports.onExecutePostLogin = async (event, api) => {
      const namespace = 'https://my-custom-app.com/'; 
      
      try {
        let allRoles = [];
        let cursor;
        
        const params = { take: 50 };
        
        // Paginate through all roles using the next cursor
        do {
          params.from = cursor;
          const result = await api.roles.getUserEffectiveRoles(params);
          
          if (result && result.roles) {
            allRoles.push(...result.roles);
          }
          
          cursor = result?.next;
        } while (cursor);
    
        // Append roles to the tokens if any were found
        if (allRoles.length > 0) {
          const roleNames = allRoles.map(role => role.name);
          
          api.idToken.setCustomClaim(namespace + 'roles', roleNames);
          api.accessToken.setCustomClaim(namespace + 'roles', roleNames);
        }
      } catch (error) {
        console.error('Error fetching user effective roles:', error);
      }
    };
  5. Select Deploy.
  6. Navigate to Actions > Flows and select Login.
  7. Drag the new Action into the flow and select Apply.

Recommended content

No recommended content found...