MS Graph API 没有 return 来自 Azure AD B2C 的用户电子邮件地址

MS Graph API does not return user's email address from Azure AD B2C

当我使用 Microsoft Graph API 从 Azure AD B2C 获取用户时,用户注册的电子邮件地址没有出现在返回的 JSON 中。尽管 SO 中有帖子建议电子邮件地址应该存在于邮件(otherMails 或 signInNames)以外的其他字段中,但收到的 JSON 不包含任何具有预期电子邮件地址的字段。这是我 运行 对测试用户(屏蔽敏感数据)的请求:

GET https://graph.microsoft.com/v1.0/users/xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Authorization: Bearer xxxxxxxxx
Content-Type: application/json

响应中的JSON是:

{
  "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users/$entity",
  "businessPhones": [],
  "displayName": "unknown",
  "givenName": "some",
  "jobTitle": null,
  "mail": null,
  "mobilePhone": null,
  "officeLocation": null,
  "preferredLanguage": null,
  "surname": "user",
  "userPrincipalName": "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx@xxxxx.onmicrosoft.com",
  "id": "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}

尽管如此,当我在 Azure AD B2C 中看到用户时,电子邮件地址显示在用户列表页面的 "User name" 列下:

并且当我查看用户的个人资料时,电子邮件地址也会显示在 "User Principal Name" 字段下:

电子邮件来自哪里,我如何使用 MS Graph 获取它API?

您可以使用 Beta 端点从身份集合中获取用户名。

查询

https://graph.microsoft.com/beta/users/userid?select=identities

请仔细阅读 articles