You can add custom attribute for user in Azure AD B2B using Microsoft Graph API extentionProperty
While creating extension , specify targetObjects "User" to add the attribute for every user .
Pre-requisites : Application should be registered in Azure AD and has Directory.ReadWrite.All permissions to add custom property to directory objects.
1) Create Extension Property using POST request
https://graph.microsoft.com/v1.0/applications/{object-id of application}/extensionProperties
Request Body:
{
"name": "extensionName",
"dataType": "string",
"targetObjects": [
"User"
]
}
In response you will get "name": "extension_xxxx_extensionName"
Once attribute has been created, you can update value for each user using below:
2) Patch request:
https://graph.microsoft.com/v1.0/users/{user id}
{
"extension_xxxx_extensionName": "isPresent"
}
To list attribute added in user profile using:
Get request:
https://graph.microsoft.com/beta/users/{username}@{tenant-id}.onmicrosoft.com
"refreshTokensValidFromDateTime": "2021-09-25T17:28:14Z",
"showInAddressList": null,
"signInSessionsValidFromDateTime": "2021-09-25T17:28:14Z",
"state": null,
"streetAddress": null,
"surname": "bbbb",
"usageLocation": "IN",
"userPrincipalName": "shweta@X .onmicrosoft.com",
"externalUserState": null,
"externalUserStateChangeDateTime": null,
"userType": "Member",
"extension_xxx_extensionName": "isPresent",
"employeeOrgData": null,
"passwordProfile": null,