Im trying to add additional claim mapping to an app registration, Ive created in my tenant.
$app = Get-AzureADApplication -ObjectId <obj-id>
$policy = New-Object Microsoft.Open.AzureAD.Model.ClaimsMappingPolicy
$policy.InputClaims = @(
(New-Object Microsoft.Open.AzureAD.Model.InputClaim).Type("email")
)
$policy.OutputClaims = @(
(New-Object Microsoft.Open.AzureAD.Model.OutputClaim).Type("t24user")
)
$policy.ClaimMappings = @(
(New-Object Microsoft.Open.AzureAD.Model.ClaimMapping).InputClaimType("email").OutputClaimType("t24user").TransformationMethod("ExtractPrefixFromEmail")
)
Im getting the following error when I run this on line 2
$policy = New-Object Microsoft.Open.AzureAD.Model.ClaimsMappingPolicy
At line:1 char:11
+ $policy = New-Object -TypeName Microsoft.Open.AzureAD.Model.ClaimsMap ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException
+ FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand
I tried to re-install AzureAD module and also tried with installing AzureADPreivew Module also. But it was not helping. Appreciate help here.
I tried to reproduce the same in my environment and got below results:
When I ran same PowerShell script as you, I got same error like below:
Response:
Alternatively, you can make use of New-AzureADPolicy command that requires
AzureADPreviewmodule.To install that module, you need to uninstall
AzureADmodule like below:Now run below Powershell command to create claim mapping policy:
Note the
IDof the policy from above response and assign it to your service principal using below command:To confirm whether the policy is assigned or not, you can run below command:
Response:
I assigned value to above claim by running this Graph query:
Make sure to set
"acceptMappedClaims": truein App's Manifest like below:Go to Azure Portal -> Azure Active Directory -> App registrations -> Your App -> Manifest
Now, I generated token for above application and got claim successfully after decoding it in jwt.ms website like below: