Azure AD - Custom Claims in Access Tokens

Thorsten 21 Reputation points
2020-10-22T11:46:04.68+00:00

Hello,

we have the requirement to add custom claims to access_tokens (jwt).
The claims (constant names and values) should be defined per app. Every time an access_token for the app is requested the claims should be added to the token.
Is it possible to define such claims for an app?

Thank You.

Regards,
Thorsten

Microsoft Security | Microsoft Entra | Microsoft Entra ID
0 comments No comments
{count} votes

Accepted answer
  1. Alfredo Revilla - Upwork Top Talent | IAM SWE SWA 27,526 Reputation points Moderator
    2020-10-22T16:24:33.737+00:00

    You can create a custom claim mapping policy with a definition similar to this:

       {  
         "ClaimsMappingPolicy":  
           {   
             "Version":1,  
             "IncludeBasicClaimSet":"true",   
             "ClaimsSchema":[{"value":"myConstantValue","JwtClaimType":"myClaim"}]  
           }  
       }  
    

    And assign it to your application service principal.

    --
    Please let us know if this answer was helpful to you. If so, please remember to mark it as the answer so that others in the community with similar questions can more easily find a solution.

    0 comments No comments

4 additional answers

Sort by: Most helpful
  1. AmanpreetSingh-MSFT 56,871 Reputation points Moderator
    2020-10-22T16:02:09.317+00:00

    Hi @Thorsten · You can update app manifest for this purpose. When configuring directory extension optional claims using the application manifest, use the full name of the extension (in the format: extension_<appid>_<attributename>). The <appid> must match the ID of the application requesting the claim.

    Within the JWT, these claims will be emitted with the following name format: extn.<attributename>.

    Within the SAML tokens, these claims will be emitted with the following URI format: http://schemas.microsoft.com/identity/claims/extn.<attributename>

    Below is an example of how to update app manifest to pass custom attribute in Access Token:

    "optionalClaims": {  
        "accessToken": [  
            {  
                "name": ""extension_ab603c56068041afb2f6832e2a17e237_CustomAttrib"",  
                "essential": false  
            }  
        ]  
    }  
    

    -----------------------------------------------------------------------------------------------------------

    Please "Accept the answer" if the information helped you. This will help us and others in the community as well.

    0 comments No comments

  2. Heike 1 Reputation point
    2020-10-27T13:24:10.413+00:00

    Hi,

    I have the same requirement.
    I need a custom claim with fix value for one registered app.

    @Thorsten did one of the answers work at your place?

    @AmanpreetSingh-MSFT I tried your solution, but the jwt token still does not contain the new claim.

    anonymous user-msft is there a possibility without using powershell to do this claim policy mapping?

    Thanks in advance.

    Regards.

    0 comments No comments

  3. Thorsten 21 Reputation points
    2020-11-02T16:56:24.603+00:00

    Hi,

    sorry for the late response.

    anonymous user-msft solution works for us.

    Thanks.

    Regards

    0 comments No comments

  4. Paahn 0 Reputation points
    2023-06-21T18:14:22.89+00:00

    @AmanpreetSingh-MSFT extension_<appid>_<attributename>). The <appid> must match the ID of the application requesting the claim.

    @AmanpreetSingh-MSFT Is there any possible way to add custom claims with Directory extension as source to a different application registered in the same tenant? In other words, if I have Directory extensions on application A, can I create an application B and add those directory extensions as token claims in B?

    The reason to do this is application A has the directory extensions, and we are sharing a secret to Keycloak to act as an intermediary. We would rather give Keycloak a new clientId and secret so Keycloak doesn't have access to application A secret to read and write any data on extension properties defined there. Is there another way to achieve this?

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.