首页 文章

如何使用Graph API阅读Azure B2C自定义属性(与Azure AD Graph一起使用)

提问于
浏览
1

截至今天,文档建议使用Microsoft Graph而不是Azure AD Graph API来访问Azure AD / B2C资源 .

之前,使用Azure AD Graph API,我们可以使用像https://graph.windows.net/[tenant]/users/1a2a9c4d-fc59-4fd9-ad14-b72b549cdf6a?api-version=2013-11-08这样的查询

响应包括Azure B2C自定义属性(在Azure门户上创建)

{
        "odata.metadata": "https://graph.windows.net/<tenant>/$metadata#directoryObjects/Microsoft.DirectoryServices.User",
        "value": [
            {
                "objectId": "00000eab-603a-4de2-9d25-d3821e7d6583",
                ...
                "extension_3a4189d71ad149c6ab5e65ac45bd6add_MyAttribute1": "something"
            }
        ] 
}

使用Graph API不会发生这种情况,只返回一些"basic"属性https://graph.microsoft.com/v1.0/users/00000eab-603a-4de2-9d25-d3821e7d6583

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users/$entity",
    "id": "00000eab-603a-4de2-9d25-d3821e7d6583",
    ...
}

还尝试显式选择属性,但不返回扩展值

... graph.microsoft.com/v1.0/users/00000eab-603a-4de2-9d25-d3821e7d6583/?$select=id,extension_3a4189d71ad149c6ab5e65ac45bd6add_MyAttribute1

我们如何使用Graph API读取Azure B2C自定义属性?

2 回答

  • 2
  • 0

    返回自定义属性:

    Request

    GET https://graph.windows.net/mytenant.onmicrosoft.com/users/8b2ceb5d-4f45-4e42-b979-419119df4eaf?api-version=1.6
    

    Response

    {
          "odata.type": "Microsoft.DirectoryServices.User",
          "objectType": "User",
          "objectId": "8b2ceb5d-4f45-4e42-b979-419119df4eaf",
          ...
          "userType": "Member",
          "extension_5c5668a4ddb44c27b0d55cb412c41787_loyaltyId": "some value from the demo"
    }
    

    来源:这是来自sample app: B2C-GraphAPI-DotNet


    Lookup Extension Guid 通过Azure门户

    how to get to azure ad app registrations

    azure ad app registrations

    以上内容适用于内置策略 .

相关问题