我正在研究客户端凭据流来验证两个应用程序,但我想在访问 token 中添加一些信息。我们可以自定义声明并将其包含在访问 token 中吗?
最佳答案
我尝试在我的环境中重现相同内容,以在 Azure AD 中创建自定义声明
请按照以下步骤获取访问 token
您可以像下面这样获取服务主体 ID 的对象 ID
Azure 门户>Azure Active Directory>企业应用程序>选择您的应用程序
( /image/5KEcs.png )
更改 list 中的值,如下所示
( /image/gIn3f.png )
使用 powershell 创建策略,如下所示
$Policy = New-AzureADPolicy -Definition @('{"ClaimsMappingPolicy":{"Version":1,"IncludeBasicClaimSet":"true", "ClaimsSchema": [{"Source":"user","ID":"customvalue","JwtClaimType":"customclaim"}]}}') -DisplayName "Demo123" -Type "ClaimsMappingPolicy"
Add-AzureADServicePrincipalPolicy -RefObjectId $Policy.Id -Id '<Service Principle ID>'
( /image/fepdC.png )
生成代码并复制代码通过postman生成token
https://login.microsoftonline.com/Tenant ID/v2.0/authorize?
&client_id=Client ID&response_type=code
&redirect_uri=https://jwt.ms
&response_mode=query
&scope=https://graph.microsoft.com/.default
&state=12345
( /image/htfsK.png )
请更改Postman中的值以生成Token
( /image/QZSk5.png )
从 postman 处复制不带引号的访问 token 值
( /image/N80kf.png )
在 jwt.ms 中解码相同的访问 token 值
( /image/sD1Bo.png )
关于azure - 是否可以在客户端凭据流程中添加自定义声明?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74516993/