Adding custom claims to JWT token for App Registration using ClaimsMappingPolicy (OIDC Auth Code Flow)

Matt Rasmussen 0 Reputation points
2023-03-22T14:20:45.3533333+00:00

This article shows the process I am familiar with when adding a custom claim such as EmployeeID to the JWT token that is passed in the OIDC auth code flow: https://learn.microsoft.com/en-us/answers/questions/260800/custom-static-claim-in-jwt-token

However Claims mapping policies link referred to on this post above no longer contains information on how to add the claim via the claims mapping policy in Azure AD Powershell. In fact it redirects to information on SAML now. This change to the documentation occurred right around the end of January.

It doesn't appear that Microsoft has deprecated this functionality, so is there a reason this information has been removed from the learn.microsoft.com portal?

Thanks

Microsoft Security Microsoft Entra Microsoft Entra ID
{count} votes

1 answer

Sort by: Most helpful
  1. Alfredo Revilla - Upwork Top Talent | IAM SWE SWA 27,526 Reputation points Moderator
    2023-03-23T05:42:03.4433333+00:00

    Hello @Matt Rasmussen , claims mapping policy PowerShell samples used the Azure AD PowerShell module which is being replaced by the Microsoft Graph PowerShell SDK. You can find samples for the latter in the Microsoft Graph documentation. Go to the Examples section and select the PowerShell tab for any.

    Import-Module Microsoft.Graph.Identity.SignIns
    
    $params = @{
    	Definition = @(
    		"{"ClaimsMappingPolicy":{"Version":1,"IncludeBasicClaimSet":"true","ClaimsSchema": [{"Source":"user","ID":"userprincipalname","SamlClaimType":"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier"},{"Source":"user","ID":"givenname","SamlClaimType":"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname"},{"Source":"user","ID":"displayname","SamlClaimType":"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name"},{"Source":"user","ID":"surname","SamlClaimType":"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname"},{"Source":"user","ID":"userprincipalname","SamlClaimType":"username"}],"ClaimsTransformation":[{"ID":"CreateTermsOfService","TransformationMethod":"CreateStringClaim","InputParameters": [{"ID":"value","DataType":"string", "Value":"sandbox"}],"OutputClaims":[{"ClaimTypeReferenceId":"TOS","TransformationClaimType":"createdClaim"}]}]}}"
    	)
    	DisplayName = "Test1234"
    }
    
    New-MgPolicyClaimMappingPolicy -BodyParameter $params
    

    Alternatively you can use the Azure Portal UI as detailed in Customize claims issued in the JSON web token (JWT) for enterprise applications (Preview)

    Let us know if you need additional assistance. If the answer was helpful, please accept it and rate it so that others facing similar issues can more easily find a solution.


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.