来自 Microsoft Entra ID 的静态自定义声明

问题描述 投票:0回答:1

我在 Microsoft Entra ID 上有一个具有自定义声明静态属性的应用程序,但我无法在访问令牌中获取这些声明。

我已经更新了清单文件:

{
    "acceptMappedClaims": true,
    "accessTokenAcceptedVersion": 2,
}

但我仍然没有在应用程序中定义自定义声明。

我尝试在清单文件中手动添加自定义声明,但无法为自定义声明提供值。

azure-active-directory microsoft-entra-id
1个回答
0
投票

我在 Microsoft Entra ID 上有一个具有自定义声明静态属性的应用程序,但我无法在访问令牌中获取这些声明。

在我的环境中,我使用以下 powershell 脚本创建了策略。

脚本:

New-AzureADPolicy -Definition @('
{
    "ClaimsMappingPolicy":
    {
        "Version":1,"IncludeBasicClaimSet":"true", 
        "ClaimsSchema": [{"Source":"user","ID":"extensionattribute1","SamlClaimType":"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/employeeid","JwtClaimType":"staffid"}]
    }
}') -DisplayName "staffid" -Type "ClaimsMappingPolic

Add-AzureADServicePrincipalPolicy  -RefObjectId 'PolicyID' -Id 'ServicePrincipalObjID'

命令与输出:

PS C:\Users\xxxxx> New-AzureADPolicy -Definition @('
{
    "ClaimsMappingPolicy":
    {
        "Version":1,"IncludeBasicClaimSet":"true", 
        "ClaimsSchema": [{"Source":"user","ID":"extensionattribute1","SamlClaimType":"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/employeeid","JwtClaimType":"staffid"}]
    }
}') -DisplayName "staffid" -Type "ClaimsMappingPolicy"

Id                                   DisplayName Type                IsOrganizationDefault
--                                   ----------- ----                ---------------------
02dxxxxxx19xxxae16f7a staffid     ClaimsMappingPolicy False                

PS C:\Users\vxxxxu> Add-AzureADServicePrincipalPolicy  -RefObjectId '02d1289e-9xxxxxx7a' -Id '9e4fd06dxxxxxx46-43a712de6e21'
PS C:\Users\xxxxu> 

现在,我将其分配给具有如下请求的用户:

PATCH https://graph.microsoft.com/v1.0/me
{
    "onPremisesExtensionAttributes": {
        "extensionAttribute1": "EMP456728"
    }
}

enter image description here

根据此MS-Document

要在访问令牌中显示自定义声明,您需要通过应用程序注册为具有自定义 Api 范围的应用程序生成令牌。

传送门: enter image description here

现在,当我使用以下参数通过 Postman 生成令牌时:

Grant type: Authorization code 

Callback URL: https://oauth.pstmn.io/v1/callback
Auth URL:  https://login.microsoftonline.com/TenantId/oauth2/v2.0/authorize
Token URL : https://login.microsoftonline.com/TenantId/oauth2/v2.0/token
Client ID : FrontEndClientID
Client Secret : ClientSecret
Scope: api://efxxxxxxxx5a9c4ccf/sample.read openid

我从上述请求中同时得到了

access token
id token

enter image description here

现在,当我解码访问令牌时,我可以获得声明值。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.