Hi Robert Vedin,
Hi, Thank you for posting your query on Microsoft Q&A. I am Saiteja from Q&A will be assisting you with your query.
Based on your query, here is my understanding: You would like to pass application display name as a claim for client credential flow application.
I see you have tried using optional claims which are actually for the user authentication protocals. Optional claims only support user-based claims which means you cannot add appname
.
Since client credential flow does not support optional claims, I would recommend you check with claims mapping policy to achieve the end goal.
Here are the steps you can follow:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Install-Module Microsoft.Graph -Scope CurrentUser -Repository PSGallery -Force
Get-InstalledModule Microsoft.Graph
Import-Module Microsoft.Graph.Identity.SignIns
Connect-MgGraph -Scopes "Policy.ReadWrite.ApplicationConfiguration", "Policy.Read.All"
New-MgPolicyClaimMappingPolicy -Definition @('{"ClaimsMappingPolicy"{"Version":1,"IncludeBasicClaimSet":"false"}}') -DisplayName "OmitBasicClaims"
New-MgPolicyClaimMappingPolicy -Definition @('{"ClaimsMappingPolicy":{"Version":1,"IncludeBasicClaimSet":"true", "ClaimsSchema": [{"Source":"user","ID":"employeeid","SamlClaimType":"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/employeeid","JwtClaimType":"employeeid"},{"Source":"company","ID":"tenantcountry","SamlClaimType":"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/country","JwtClaimType":"country"}]}}') -DisplayName "ExtraClaimsExample"
Here in the above command, you need to change the source
as "Application" and ID "Appdisplayname".
Now you can check the same policy and copy the policy ID: Get-MgPolicyClaimMappingPolicy
To assign the policy to the service principal you will need the ObjectId
of your claims mapping policy and the objectId
of the service principal to which the policy must be assigned.
New-MgServicePrincipalClaimMappingPolicyByRef -ServicePrincipalId <servicePrincipalId> -BodyParameter @{"@odata.id" = "https://graph.microsoft.com/v1.0/policies/claimsMappingPolicies/<claimsMappingPolicyId>"}
Here is the Microsoft document which help you in getting in detailed explanation of the above policy configuration.
I hope this information is helpful. Please feel free to reach out if you have any further questions.
If the answer is helpful, please click "Accept Answer" and kindly "upvote it". If you have extra questions about this answer, please click "Comment"