【问题标题】:Azure B2C: Graph API doesn't always return userAzure B2C:图形 API 并不总是返回用户
【发布时间】:2021-06-11 03:16:59
【问题描述】:

在向 Azure B2C Graph API 查询以检索特定用户时,我注意到有时不会返回任何结果,但会从 Graph API 服务器返回 HTTP 200 代码。每次我们需要调用 Graph API 时,我们的服务器都会创建一个 Graph API 令牌(将来会处理,但这可能是我遇到以下问题的原因)。

这些问题大多发生在我们用 Python 编写的集成测试期间。

首先,我们在 Azure B2C 中创建用户:

Inserting test user with data:  {
   "accountEnabled":true,
   "displayName":"Patricia Robles",
   "mailNickname":"PatriciaRobles",
   "extension_<id>_organizationId":"b5468371-54e7-41d3-8dc4-904779417ce2",
   "extension_<id>_organizationName":"My Organization",
   "extension_<id>_username":"PatriciaRobles",
   "givenName":"Patricia",
   "surname":"Robles",
   "userPrincipalName":"PatriciaRobles@testb2c.onmicrosoft.com",
   "passwordProfile":{
      "password":"He#02021"
   }
}
Created in Graph API:  {
   "@odata.context":"https://graph.microsoft.com/v1.0/$metadata#users/$entity",
   "id":"5e2ae56c-4493-451f-be26-de51e05475c5",
   "businessPhones":[
      
   ],
   "displayName":"Patricia Robles",
   "givenName":"Patricia",
   "jobTitle":"None",
   "mail":"None",
   "mobilePhone":"None",
   "officeLocation":"None",
   "preferredLanguage":"None",
   "surname":"Robles",
   "userPrincipalName":"PatriciaRobles@testb2c.onmicrosoft.com"
}

所以看起来它实际上是在 Azure B2C 中创建了用户。请注意,我实际上更改了实际运行时的值以防止泄露敏感数据。

现在,作为测试期间的健全性检查,我想查询组织中的所有用户:

https://graph.microsoft.com/v1.0/users?$select=identities,givenName,id,surname&$filter=extension_<id>_organizationId eq 'b5468371-54e7-41d3-8dc4-904779417ce2'
Returned for Graph API:  {'@odata.context': 'https://graph.microsoft.com/v1.0/$metadata#users(identities,givenName,id,surname)', "value":[
   {
      "givenName":"Patricia",
      "id":"5e2ae56c-4493-451f-be26-de51e05475c5",
      "surname":"Robles",
      "identities":[
         {
            "signInType":"userPrincipalName",
            "issuer":"testb2c.onmicrosoft.com",
            "issuerAssignedId":"PatriciaRobles@testb2c.onmicrosoft.com"
         }
      ]
   },
   {
      "givenName":"Ruby",
      "id":"a7b2d2fe-3176-49bc-9775-691195ed9002",
      "surname":"Woodard",
      "identities":[
         {
            "signInType":"userPrincipalName",
            "issuer":"testb2c.onmicrosoft.com",
            "issuerAssignedId":"RubyWoodard@testb2c.onmicrosoft.com"
         }
      ]
   },
   {
      "givenName":"Helen",
      "id":"d97201c8-e561-4b83-aa75-441ccc069a18",
      "surname":"Charles",
      "identities":[
         {
            "signInType":"userPrincipalName",
            "issuer":"testb2c.onmicrosoft.com",
            "issuerAssignedId":"HelenCharles@testb2c.onmicrosoft.com"
         }
      ]
   }
]
}

用户肯定存在于 Azure B2C 中。所以我们绝对应该能够查询那个单独的用户,对吧?

嗯,不完全是:

https://graph.microsoft.com/v1.0/users?$select=identities,givenName,id,surname&$filter=extension_5d0e560b4ba9481d97b55226dd4c411a_organizationId eq 'b5468371-54e7-41d3-8dc4-904779417ce2' and id eq '5e2ae56c-4493-451f-be26-de51e05475c5'
Returned for Graph API:  {'@odata.context': 'https://graph.microsoft.com/v1.0/$metadata#users(identities,givenName,id,surname)', 'value': []}
Retrieved from Graph API:  {}

所以现在,没有用户通过 Graph API 从 Azure B2C 返回。

为什么会发生这种情况?

【问题讨论】:

    标签: azure azure-active-directory azure-ad-b2c azure-ad-graph-api


    【解决方案1】:

    这是一项全球分布式服务,您正在访问用户尚未复制到的不同 DC。用户出现在该地区的所有 DC 中可能需要几秒钟时间。

    这是预期的行为,您必须在设计解决方案时牢记这一点。您可以使用重试逻辑,但最好不要在 POST/PATCH 操作之后执行 GET。

    理想情况下,您可以通过不存在此问题的 AAD B2C 策略来安排注册。

    【讨论】:

    • @jas-suri-msft,我是否将client-request-id 放在GET 操作的标题中?似乎我仍然收到那些随机错误。我需要使用Location吗?
    • 另外,真的有关于这些东西的文档吗?
    • 您可能需要在您的 POST 请求中生成一个 client-request-id 标头。然后在 GET 请求中发送相同的标头。
    • @jas-suri-msft,嗯...似乎我用这种方法遇到了同样的问题。我已经查看了文档,但我并没有真正看到任何关于这种行为的参考。这是在哪里记录的?
    • 我将在此基础上编辑此答案。这种方法没有记录。
    猜你喜欢
    • 1970-01-01
    • 2018-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-09
    • 1970-01-01
    相关资源
    最近更新 更多