Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this page

Pass Custom Azure AD Attributes as Twilio Flex SAML Claims


Azure AD extension properties can only be used as Enterprise Application SAML claims through a Claims Mapping Policy(link takes you to an external page) created using the Graph API or Powershell. The Azure AD portal interface does not support adding extension properties as claims. This guide uses the Graph API to walk you through the process of creating an Azure AD extension property, a claims mapping policy, and passing the property as a custom attribute for your Flex users.


Open Microsoft Graph Explorer

open-microsoft-graph-explorer page anchor
  1. Open and login to your Azure portal(link takes you to an external page) .
  2. In a separate tab, open the Microsoft Graph API Explorer(link takes you to an external page), click "Sign in to Graph Explorer", and select your Azure administrator account to use for Graph Explorer.

    graph-explorer-signin.
  3. Make sure to consent to the following permissions requirements(link takes you to an external page):

    msgraph-consent.

We will need to retrieve a couple IDs for use in the next steps: your Service principal entity ID and your Application entity ID. Click on the respective tab for detailed instructions.

Service Principal Entity IDApplication Entity ID

Run the following Graph Explorer query to retrieve your Service Principal Entity ID. Make sure to:

  • Replace with a portion of your Enterprise app name on the URL field. For example, if your app name is "Twilio Flex", you can enter "displayname
    " as the $search query parameter value.
  • Click on the Request headers tab to add the key-value pair.

Example Request


_10
HTTP method: GET
_10
API version: v1.0
_10
Endpoint URL: https://graph.microsoft.com/v1.0/servicePrincipals?$search="displayName:<Your_App_Name>"
_10
Request header key: ConsistencyLevel
_10
Request header value: eventual

  • Click Run query and in the JSON response, look for the array object whose " appDisplayName " value matches your Enterprise Application name.
  • Copy the " id " value and paste it somewhere you can reference it.

Example Response


_152
{
_152
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#servicePrincipals",
_152
"value": [
_152
{
_152
"id": "cdxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
_152
"deletedDateTime": null,
_152
"accountEnabled": true,
_152
"alternativeNames": [],
_152
"appDisplayName": "Twilio Flex testing",
_152
"appDescription": null,
_152
"appId": "xxx",
_152
"applicationTemplateId": "xxx",
_152
"appOwnerOrganizationId": "xxx",
_152
"appRoleAssignmentRequired": true,
_152
"createdDateTime": "2021-11-24T18:17:10Z",
_152
"description": null,
_152
"disabledByMicrosoftStatus": null,
_152
"displayName": "Twilio Flex testing",
_152
"homepage": "https://account.activedirectory.windowsazure.com:444/applications/default.aspx?metadata=customappsso|ISV9.1|primary|z",
_152
"loginUrl": null,
_152
"logoutUrl": null,
_152
"notes": null,
_152
"notificationEmailAddresses": [
_152
"user@userdomain.onmicrosoft.com"
_152
],
_152
"preferredSingleSignOnMode": "saml",
_152
"preferredTokenSigningKeyThumbprint": "xxxx",
_152
"replyUrls": [
_152
"https://iam.twilio.com/v1/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/saml2/"
_152
],
_152
"servicePrincipalNames": [
_152
"https://iam.twilio.com/v1/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/saml2/metadata",
_152
"xxx"
_152
],
_152
"servicePrincipalType": "Application",
_152
"signInAudience": "AzureADMyOrg",
_152
"tags": [
_152
"WindowsAzureActiveDirectoryCustomSingleSignOnApplication",
_152
"WindowsAzureActiveDirectoryIntegratedApp"
_152
],
_152
"tokenEncryptionKeyId": null,
_152
"resourceSpecificApplicationPermissions": [],
_152
"verifiedPublisher": {
_152
"displayName": null,
_152
"verifiedPublisherId": null,
_152
"addedDateTime": null
_152
},
_152
"addIns": [],
_152
"appRoles": [
_152
{
_152
"allowedMemberTypes": [
_152
"User"
_152
],
_152
"description": "admin",
_152
"displayName": "Admin",
_152
"id": "yyy",
_152
"isEnabled": true,
_152
"origin": "Application",
_152
"value": "admin"
_152
},
_152
{
_152
"allowedMemberTypes": [
_152
"User"
_152
],
_152
"description": "supervisor",
_152
"displayName": "Supervisor",
_152
"id": "zzz",
_152
"isEnabled": true,
_152
"origin": "Application",
_152
"value": "supervisor"
_152
},
_152
{
_152
"allowedMemberTypes": [
_152
"User"
_152
],
_152
"description": "agent",
_152
"displayName": "Agent",
_152
"id": "aaa",
_152
"isEnabled": true,
_152
"origin": "Application",
_152
"value": "agent"
_152
},
_152
{
_152
"allowedMemberTypes": [
_152
"User"
_152
],
_152
"description": "msiam_access",
_152
"displayName": "msiam_access",
_152
"id": "bbb",
_152
"isEnabled": true,
_152
"origin": "Application",
_152
"value": null
_152
}
_152
],
_152
"info": {
_152
"logoUrl": null,
_152
"marketingUrl": null,
_152
"privacyStatementUrl": null,
_152
"supportUrl": null,
_152
"termsOfServiceUrl": null
_152
},
_152
"keyCredentials": [
_152
{
_152
"customKeyIdentifier": "xxx",
_152
"displayName": "CN=Microsoft Azure Federated SSO Certificate",
_152
"endDateTime": "2024-11-24T18:24:49Z",
_152
"key": null,
_152
"keyId": "xxx",
_152
"startDateTime": "2021-11-24T18:24:49Z",
_152
"type": "AsymmetricX509Cert",
_152
"usage": "Verify"
_152
},
_152
{
_152
"customKeyIdentifier": "xxx",
_152
"displayName": "CN=Microsoft Azure Federated SSO Certificate",
_152
"endDateTime": "2024-11-24T18:24:49Z",
_152
"key": null,
_152
"keyId": "xxx",
_152
"startDateTime": "2021-11-24T18:24:49Z",
_152
"type": "AsymmetricX509Cert",
_152
"usage": "Sign"
_152
}
_152
],
_152
"oauth2PermissionScopes": [
_152
{
_152
"adminConsentDescription": "Allow the application to access Twilio Flex testing on behalf of the signed-in user.",
_152
"adminConsentDisplayName": "Access Twilio Flex testing",
_152
"id": "xxx",
_152
"isEnabled": true,
_152
"type": "User",
_152
"userConsentDescription": "Allow the application to access Twilio Flex testing on your behalf.",
_152
"userConsentDisplayName": "Access Twilio Flex testing",
_152
"value": "user_impersonation"
_152
}
_152
],
_152
"passwordCredentials": [
_152
{
_152
"customKeyIdentifier": "xxx",
_152
"displayName": "CN=Microsoft Azure Federated SSO Certificate",
_152
"endDateTime": "2024-11-24T18:24:49Z",
_152
"hint": null,
_152
"keyId": "xxx",
_152
"secretText": null,
_152
"startDateTime": "2021-11-24T18:24:49Z"
_152
}
_152
],
_152
"samlSingleSignOnSettings": {
_152
"relayState": ""
_152
}
_152
}
_152
]
_152
}


Create Azure AD Extension Property

create-azure-ad-extension-property page anchor

In this section, we're going to create an extended (custom) property for the Enterprise Application that we can then populate for our target Flex users.

Run the following Graph Explorer query. Make sure to:

  • In the URL field, replace <Application_Entity_ID> with the application entity ID you noted earlier.
  • Click on the Request body tab to add the JSON in the Request body field. Replace <Property_Name> with the name you want to use for the extension.

Example Request

example-request-3 page anchor

_10
HTTP method: POST
_10
API version: v1.0
_10
Endpoint URL: https://graph.microsoft.com/v1.0/applications/<Application_Entity_ID>/extensionProperties
_10
Request body:
_10
{
_10
"name": "<Property_Name>",
_10
"dataType": "String",
_10
"targetObjects": ["User"]
_10
}

Click Run query and in the JSON response, copy and paste the "name" value of the new extension property for reference in later steps. It will be in the format "extension_<App_ID>_<Property_Name>".


_12
{
_12
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#applications('xxx')/extensionProperties/$entity",
_12
"id": "xxx",
_12
"deletedDateTime": null,
_12
"appDisplayName": "Twilio Flex testing",
_12
"dataType": "String",
_12
"isSyncedFromOnPremises": false,
_12
"name": "extension_xxx_language",
_12
"targetObjects": [
_12
"User"
_12
]
_12
}


Populate Extension Property on Azure AD User

populate-extension-property-on-azure-ad-user page anchor

Now that we have an extension property created, let's add it to a user.

Run the following Graph Explorer query. Make sure to:

  • In the URL field, you can pass either the user ID or the user principal name (UPN). Replace <ID \| UserPrincipalName> with either the object ID or the UPN of the Azure AD user you want to update.
  • Click on the Request body tab to add the JSON in the Request body field.

    • Replace <extension_<App_ID>_<Property_Name> with the name of the extension property created in the previous step.
    • Replace "My Custom Value" with the value you want to assign to this property.

_10
HTTP method: PATCH
_10
API version: v1.0
_10
Endpoint URL: https://graph.microsoft.com/v1.0/users/<ID | UserPrincipalName>
_10
Request body:
_10
{
_10
"extension_<App_ID>_<Property_Name>": "My Custom Value"
_10
}

Click Run query.


_10
204 {}

To confirm the user was updated successfully, run the following query.


_10
HTTP method: GET
_10
API version: beta
_10
Endpoint URL: https://graph.microsoft.com/beta/users/<ID | UserPrincipalName>

In the JSON response, you should see the new extension property and assigned value in the user's properties.


_88
{
_88
"@odata.context": "https://graph.microsoft.com/beta/$metadata#users/$entity",
_88
"id": "xxxx",
_88
"deletedDateTime": null,
_88
"accountEnabled": true,
_88
"ageGroup": null,
_88
"businessPhones": [],
_88
"city": null,
_88
"createdDateTime": "2021-11-19T06:55:28Z",
_88
"creationType": null,
_88
"companyName": null,
_88
"consentProvidedForMinor": null,
_88
"country": null,
_88
"department": null,
_88
"displayName": "Test User",
_88
"employeeId": null,
_88
"employeeHireDate": null,
_88
"employeeType": null,
_88
"faxNumber": null,
_88
"givenName": "Test",
_88
"imAddresses": [],
_88
"infoCatalogs": [],
_88
"isManagementRestricted": null,
_88
"isResourceAccount": null,
_88
"jobTitle": null,
_88
"legalAgeGroupClassification": null,
_88
"mail": null,
_88
"mailNickname": "testuser",
_88
"mobilePhone": null,
_88
"onPremisesDistinguishedName": null,
_88
"officeLocation": null,
_88
"onPremisesDomainName": null,
_88
"onPremisesImmutableId": null,
_88
"onPremisesLastSyncDateTime": null,
_88
"onPremisesSecurityIdentifier": null,
_88
"onPremisesSamAccountName": null,
_88
"onPremisesSyncEnabled": null,
_88
"onPremisesUserPrincipalName": null,
_88
"otherMails": [],
_88
"passwordPolicies": null,
_88
"postalCode": null,
_88
"preferredDataLocation": null,
_88
"preferredLanguage": null,
_88
"proxyAddresses": [],
_88
"refreshTokensValidFromDateTime": "2021-11-24T19:10:02Z",
_88
"showInAddressList": null,
_88
"signInSessionsValidFromDateTime": "2021-11-24T19:10:02Z",
_88
"state": null,
_88
"streetAddress": null,
_88
"surname": "User",
_88
"usageLocation": null,
_88
"userPrincipalName": "testuser@admintwilio.onmicrosoft.com",
_88
"externalUserState": null,
_88
"externalUserStateChangeDateTime": null,
_88
"userType": "Member",
_88
"extension_xxx_language": "Russian",
_88
"employeeOrgData": null,
_88
"passwordProfile": null,
_88
"assignedLicenses": [],
_88
"assignedPlans": [],
_88
"deviceKeys": [],
_88
"identities": [
_88
{
_88
"signInType": "userPrincipalName",
_88
"issuer": "admintwilio.onmicrosoft.com",
_88
"issuerAssignedId": "testuser@admintwilio.onmicrosoft.com"
_88
}
_88
],
_88
"onPremisesExtensionAttributes": {
_88
"extensionAttribute1": null,
_88
"extensionAttribute2": null,
_88
"extensionAttribute3": null,
_88
"extensionAttribute4": null,
_88
"extensionAttribute5": null,
_88
"extensionAttribute6": null,
_88
"extensionAttribute7": null,
_88
"extensionAttribute8": null,
_88
"extensionAttribute9": null,
_88
"extensionAttribute10": null,
_88
"extensionAttribute11": null,
_88
"extensionAttribute12": null,
_88
"extensionAttribute13": null,
_88
"extensionAttribute14": null,
_88
"extensionAttribute15": null
_88
},
_88
"onPremisesProvisioningErrors": [],
_88
"provisionedPlans": []
_88
}

(warning)

Warning

If you don't change the API version to beta, you'll only get a handful of user properties instead of the full list.


Create a Claims Mapping Policy

create-a-claims-mapping-policy page anchor

We can now create our claims mapping policy. For an example claim definition and a walkthrough of its key configuration properties, see "Example Claims Policy Definition".

Run the following Graph Explorer query. Make sure to:

  • Click on the Request body tab and enter the JSON in the Request body field. Make the following changes:


_11
HTTP method: POST
_11
API version: v1.0
_11
Endpoint URL: https://graph.microsoft.com/v1.0/policies/claimsMappingPolicies
_11
Request body:
_11
{
_11
"definition": [
_11
"{\"ClaimsMappingPolicy\":{\"Version\":1,\"IncludeBasicClaimSet\":\"true\",\"ClaimsSchema\":[{\"Source\":\"user\",\"ID\":\"userprincipalname\",\"SamlClaimType\":\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier\"},{\"Source\":\"user\",\"ID\":\"displayname\",\"SamlClaimType\":\"full_name\"},{\"Source\":\"user\",\"ID\":\"assignedroles\",\"SamlClaimType\":\"roles\"},{\"Source\":\"user\",\"ID\":\"mail\",\"SamlClaimType\":\"email\"},{\"Source\":\"user\",\"ExtensionID\":\"extension_<App_ID>_<Property_Name>\",\"SamlClaimType\":\"<Claim_Attribute_Name>\"}]}}"
_11
],
_11
"displayName": "<Claim_Policy_Name>",
_11
"isOrganizationDefault": false
_11
}

Click Run query. In the JSON response, copy the claims mapping policy "id" value and paste it somewhere you can reference it.


_11
201 Created
_11
{
_11
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#policies/claimsMappingPolicies/$entity",
_11
"id": "xxx",
_11
"deletedDateTime": null,
_11
"definition": [
_11
"{\"ClaimsMappingPolicy\":{\"Version\":1,\"IncludeBasicClaimSet\":\"true\",\"ClaimsSchema\":[{\"Source\":\"user\",\"ID\":\"userprincipalname\",\"SamlClaimType\":\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier\"},{\"Source\":\"user\",\"ID\":\"displayname\",\"SamlClaimType\":\"full_name\"},{\"Source\":\"user\",\"ID\":\"assignedroles\",\"SamlClaimType\":\"roles\"},{\"Source\":\"user\",\"ID\":\"mail\",\"SamlClaimType\":\"email\"},{\"Source\":\"user\",\"ExtensionID\":\"extension_xxx_exampleproperty\",\"SamlClaimType\":\"exampleclaimattribute\"}]}}"
_11
],
_11
"displayName": "Example Claim Policy Name",
_11
"isOrganizationDefault": false
_11
}

Assign Claims Mapping Policy to Application

assign-claims-mapping-policy-to-application page anchor

Finally, we can assign the Claims Mapping Policy we just created to your Enterprise Application.

(error)

Danger

Once you assign a Claims Mapping Policy to an Enterprise Application using Graph API or Powershell, you can no longer manage SAML claims in the Azure AD portal. Accessing the SAML claims configuration page in the Azure AD portal will result in the following error message:

"This configuration was overwritten by a claim mapping policy created via Graph/PowerShell."

Run the following Graph Explorer query. Make sure to:

  • Replace <Service_Principal_Entity_ID> with your previously retrieved Service Principal Entity ID from the "Gather supporting IDs" section.
  • Click on the Request body tab to add the JSON in the Request body field.

    • Replace <Claims_Mapping_Policy_ID> with the ID you noted previously.

_10
HTTP method: POST
_10
API version: v1.0
_10
Endpoint URL: https://graph.microsoft.com/v1.0/servicePrincipals/<Service_Principal_Entity_ID>/claimsMappingPolicies/$ref
_10
Request body:
_10
{
_10
"@odata.id": "https://graph.microsoft.com/v1.0/policies/claimsMappingPolicies/<Claims_Mapping_Policy_ID>"
_10
}

  • Click Run query and in the JSON response, look for the array object whose " appDisplayName " value matches your Enterprise Application name.
  • Copy the " id " value and paste it somewhere you can reference it.

_10
204 {}


Test New Claims Mapping Policy

test-new-claims-mapping-policy page anchor

With all of the above sections completed, you are now ready to login to Flex and test the new claims mapping policy.

  1. Navigate to the Flex Console Single Sign-on settings page(link takes you to an external page) .
  2. When redirected to Azure AD for authentication, log in with the AD user account you assigned the extension property to previously in this guide.
  3. After logging in and the Flex UI has loaded, check the TaskRouter worker attributes in the Twilio Console ( TaskRouter -> Workspace -> Workers).

    If you're seeing all the expected attributes you've defined in the Claims Mapping Policy, you have successfully configured your custom claims.

    If any attributes are missing, examine the SAML response payload after authenticating to Azure AD. Ensure all the attributes are included, and that they have values, and that the "Name" parameter is correct for each of them.

    As explained in the Twilio Flex SSO and IdP troubleshooting section, if the "Name" parameter on an attribute includes the namespace, it will be ignored. Double check your Claims Mapping Policy definition and ensure the "SamlClaimType" is defined without a namespace for each claim you want to be captured as a TaskRouter worker attribute.

Unassign Claims Mapping Policy from Application

unassign-claims-mapping-policy-from-application page anchor

If you no longer need or want to pass custom extension properties as SAML claims and you'd like to manage claims in the Azure AD portal, or you want to assign a different Claims Mapping Policy to your Enterprise application, you will need to unassign the current Claims Mapping Policy from the application.

Run the following Graph Explorer query. Make sure to:

  • In the URL field, replace <Service_Principal_Entity_ID> with your previously retrieved Service Principal Entity ID from the "Gather supporting IDs" section.

_10
HTTP method: DELETE
_10
API version: v1.0
_10
Endpoint URL: https://graph.microsoft.com/v1.0/servicePrincipals/<Service_Principal_Entity_ID>/claimsMappingPolicies/<Claims_Mapping_Policy_ID>/$ref

Click Run query.


_10
204 {}

To verify there are no Claims Mapping Policies assigned to your application, run the following query using the same Service Principal Entity ID.


_10
HTTP method: GET
_10
API version: 1.0
_10
Endpoint URL: https://graph.microsoft.com/v1.0/servicePrincipals/<Service_Principal_Entity_ID>/claimsMappingPolicies

In the JSON response, the "value" property should now show an empty array.

Example Claims Policy Definition

example-claims-policy-definition page anchor

For the claim definition JSON object in "Create a Claims Mapping Policy", let's walk through an example definition and some key configuration properties.

(warning)

Warning

For walkthrough purposes, we are displaying an unminified and unescaped claims policy definition. When creating a claims policy in Graph Explorer, you need to minify and escape the JSON object before adding it to the "definition" array. This removes traces of offending characters that could prevent parsing.


_34
{
_34
"ClaimsMappingPolicy": {
_34
"Version": 1,
_34
"IncludeBasicClaimSet": "true",
_34
"ClaimsSchema": [
_34
{
_34
"Source": "user",
_34
"ID": "userprincipalname",
_34
"SamlClaimType": "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier"
_34
},
_34
{
_34
"Source": "user",
_34
"ID": "displayname",
_34
"SamlClaimType": "full_name"
_34
},
_34
{
_34
"Source": "user",
_34
"ID": "assignedroles",
_34
"SamlClaimType": "roles"
_34
},
_34
{
_34
"Source": "user",
_34
"ID": "mail",
_34
"SamlClaimType": "email"
_34
}, {
_34
"Source": "user",
_34
"ExtensionID": "extension__",
_34
"SamlClaimType": ""
_34
}
_34
]
_34
}
_34
}
_34
_34
}

Let's take a look at the key properties in the example definition:

Property: IncludeBasicClaimSet

Description:

Controls whether all claims in the basic claim set are included in the token generated by applications using this policy. For more details, see Azure's documentation(link takes you to an external page).

Property: ClaimsSchema

Description:

Make sure to include the required attributes for Flex:email, full_name, and roles. In the Claims schema of our example definition, each item includes the following attributes:

  • "Source": The source AD object. In this example, all of the claims we're passing are coming from the "user" object.
  • "ID": For standard AD user properties, "ID" is the key and the value is the user property we're interested in For example, to pass the display name of a user, we use { “Source”: “user”, “ID”: “displayname” } , telling the policy to use the "user.displayname" property for this claim.
  • "ExtensionID": For extension properties, like the one we created earlier in this guide, "ExtensionID" is the key and the value is the extension property in the format "extension_<App_ID>_<Property_Name>".
  • "SamlClaimType": The value that will be passed in the "name" parameter of the claim attribute This value is what will be used by Flex for populating the TaskRouter worker attribute. For Flex to process it as a worker attribute, ** it must be the name only, not preceded by a namespace. **For example, if we need to populate the "team_id" TaskRouter worker attribute with a custom extension property, we use { "Source": "user", "ExtensionID": "extension_<App_ID>_<Property_Name>", "SamlClaimType": "team_id" } , telling the policy to pass a claim attribute with Name="team_id" populated with the value contained in "user.extension_<App_ID>_<Property_Name>".

Rate this page: