首页 文章

如何获得azure b2c承诺的持有人令牌声明?

提问于
浏览
1

背景

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

用户通过azure b2c登录客户端,然后客户端通过azure b2c对服务进行查询,以获取其数据 .

问题

该服务未在承载令牌中接收预期的声明 .

细节

Azure B2C表示您为给定策略选择的声明将包含在"a token"中,我认为这是承载令牌 . 下面是我选择的一些声明的屏幕截图 .
claims for my signup-or-signin policy

但是,在我从承载令牌中提取索赔时的服务中,我得不到任何承诺的索赔 . 相反,我得到下面显示的声明 .
actual claims received

我使用 UseOAuthBearerAuthentication 与github上的microsoft提供的示例相同(上面链接) .

我错过了什么吗?我如何得到b2c承诺的声明?

1 回答

  • 2

    Application Claims are included in the id_token, not the access_token (aka bearer token) .

    这意味着 Select application claims 将允许您的客户端应用程序(本机应用程序或Web应用程序)访问这些自定义声明 .

    If you want to access custom claims from your back-end service, you'll need to call the Azure AD Graph 使用客户端凭据流并调用用户 endpoints ,如下所示:

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

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

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

    例如:

    extension_e5bf5a2db0c9415cb62661a70d8f0a68_MyCustomAttribute
    

    您也可以通过图表获取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

相关问题