gpt4 book ai didi

azure - 如何获得 azure b2c promise 的不记名 token 声明?

转载 作者:行者123 更新时间:2023-12-03 01:07:01 25 4
gpt4 key购买 nike

背景

我在 azure 中注册了两个应用程序,一个是基于 Web 的客户端,另一个是基于 Web 的服务。该设置类似于此处的示例:https://github.com/Azure-Samples/active-directory-b2c-dotnet-webapp-and-webapi

用户通过 azure b2c 登录到客户端,然后客户端查询通过 azure b2c 进行身份验证的服务以获取其数据。

问题

服务未收到不记名 token 中的预期声明。

具体

Azure B2C 表示您为给定策略选择的声明将包含在“ token ”中,我认为它是不记名 token 。以下是我选择的一些声明的屏幕截图。 claims for my signup-or-signin policy

但是,在服务上,当我从不记名 token 中提取声明时,我没有得到任何 promise 的声明。相反,我得到了如下所示的声明。 actual claims received

我使用的UseOAuthBearerAuthentication与微软在github上提供的示例相同(上面链接)。

我错过了什么吗?如何获得 B2C promise 的声明?

最佳答案

应用程序声明包含在 id_token 中,而不是 access_token(又名不记名 token )中。

这意味着选择应用程序声明将允许您的客户端应用程序( native 应用程序或网络应用程序)访问这些自定义声明。

如果您想从后端服务访问自定义声明,则需要 call the Azure AD Graph 使用客户端凭据流程并调用用户端点,如下所示:

https://graph.windows.net/<yourtenant.onmicrosoft.com>/users/<userId>

并使用以下格式检索属性:

extension_<b2c-extensions-app_appId>_<customAttributeName>

例如:

extension_e5bf5a2db0c9415cb62661a70d8f0a68_MyCustomAttribute

您还可以通过 Graph 获取 B2C 租户的 b2c-extensions-app 的 ID:

https://graph.windows.net/<yourtenant.onmicrosoft.com>/applications?$filter=displayName eq 'b2c-extensions-app'

请参阅此帖子了解更多信息: Moving Azure AD B2C custom user attributes across new environments

关于azure - 如何获得 azure b2c promise 的不记名 token 声明?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45494886/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com