Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To include the onpremisessamaccountname as a claim in the JWT token for Azure AD, you need to follow these steps:

  1. Create a custom attribute in your Active Directory (AD) schema to store the onpremisessamaccountname. This can be done using the Active Directory Schema snap-in.

  2. Sync the custom attribute to Azure AD using Azure AD Connect.

  3. Create a custom application in Azure AD if you haven't already done so. This can be done using the Azure Portal.

  4. In the application manifest, add the following lines to the "appId" section:

    "optionalClaims": { "idToken": [ { "name": "onpremisessamaccountname", "source": null, "essential": false, "additionalProperties": [] } ] }

  5. Save the manifest and wait for the changes to take effect (this may take a few minutes).

  6. In your application code, use the following code to retrieve the onpremisessamaccountname claim from the JWT token:

    string onpremisessamaccountname = User.Claims.FirstOrDefault(c => c.Type == "onpremisessamaccountname")?.Value;

This code assumes that you are using the ASP.NET Core Identity framework. If you are using a different framework, you may need to modify the code accordingly.