azure - 是否可以在客户端凭据流程中添加自定义声明?

标签 azure azure-active-directory clientcredential

我正在研究客户端凭据流来验证两个应用程序,但我想在访问 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/

相关文章:

c# - 与 Microsoft.Azure.ActiveDirectory.GraphClient 相比,调用 Microsoft.Graph 时用户没有足够的数据内容

oauth-2.0 - microsoft oidc id token 的 oid 声明是否与我从 microsoft graph api 获得的 id 相同?

azure - C# - 获取图形访问 token - 使用客户端 ID、客户端 key 、范围和客户端委托(delegate)权限

Azure 文件共享无法使用 powershell 脚本连接?

azure - 将员工 ID 添加到 azure AD 中的声明中,Add-AzureADServicePrincipalPolicy 给出服务主体 ID 不存在错误

azure - 使用 Azure Active Directory 和 Azure 移动服务对 PHP Web 应用程序进行身份验证

Spring Webflux : Assertion for redirectUriTemplate to be not null, 即使我使用 OAuth 2.0 客户端凭据

python - 在python中将文件从本地上传到Azure Blob存储时出现问题

azure - 与 Azure Active Directory 之间的迁移