How to add custom claims to the Access Token using custom user Attributes.

Malvaro 105 Reputation points
2024-04-24T11:50:51.38+00:00

Good afternoon MS team,

I am writing you because I am looking for information on how to add custom claims when the application is generating JWT token, but I can't add them to the AccessToken, but I can see them in the IDToken, .

User's image

User's image

Questions:

Can I configure custom claims in my AccessToken by adding test2, mytest, t2020, etc? Is this option possible? if so, how?

I have been reading these links but to no success:

Thoughts?, insights?,

Thanks a lot

Cheers,

Moisés.

Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,569 questions
0 comments No comments
{count} votes

1 additional answer

Sort by: Most helpful
  1. Sandeep G-MSFT 14,646 Reputation points Microsoft Employee
    2024-04-25T08:55:58.65+00:00

    @Malvaro

    Thank you for posting this in Microsoft Q&A.

    You can add custom attributes to the claims and send it within an access token.

    You can follow the steps mentioned below:

    1. Create an AzureADPolicy.

    New-AzureADPolicy -Definition @('{

    "ClaimsMappingPolicy": {

    "Version": 1,

    "IncludeBasicClaimSet": "true",

    "ClaimsSchema": [{

    "Source": "user",

    "ID": "test2",

    "JwtClaimType": "test2"

    },

    {

    "Source": "user",

    "ID": "mytest",

    "JwtClaimType": "mytest"

    },

    {

    "Source": "user",

    "ID": "t2020",

    "JwtClaimType": " t2020"

    },

    {

    "Source": "user",

    "ID": "tetttteeesss",

    "JwtClaimType": " tetttteeesss"

    }

    ]

    }

    }') -DisplayName "CustomClaimsPolicy1" -Type "ClaimsMappingPolicy"

    Attach the newly created AzureADPolicy to a specific AzureAD App's Serviceprincipal for which the token would be requested for.

    Add-AzureADServicePrincipalPolicy -Id {object id of service principal} -RefObjectId {object id of policy}

    To check if the policy is successfully added to the ServicePrincipal or not:

    Get-AzureADServicePrincipalPolicy -Id "{object id of service principal}"

    Let me know if you have any further questions.

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