azure - 如何使用 Microsoft Graph API 获取 Active Directory 用户的电话号码

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

目前,我在 Azure B2C 中有一个租户,并且有一个使用电话号码和恢复电子邮件在 Active Directory 中注册用户的用户流。我正在使用 Microsoft Graph API 来获取用户列表,但是,它永远不会返回他们注册时使用的电话号码。如果我在 Active Directory 门户中查看用户,我会在用户主体名称下看到电话号码。

User as it appears in AD with the phone number under User Principal Name

但在从 Microsoft Graph API ( https://graph.microsoft.com/v1.0/user ) 返回的 JSON 中,userPrinicpalName 不是电话号码,而是一个随机字符串(可能是 OID)。

{
    "businessPhones": [],
    "displayName": "xxxxx",
    "givenName": "xxxxx",
    "jobTitle": null,
    "mail": null,
    "mobilePhone": null,
    "officeLocation": null,
    "preferredLanguage": null,
    "surname": "Saleem",
    "userPrincipalName": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d5b6a5bcb88ae6edb4b0e6b3ecb1f8ede6ece1f8e1e1b3b4f8ecb7b4ecf8e3e3e1e0b1e3e1e0e1b1e1b795adadadadfbbabbb8bcb6a7baa6bab3a1fbb6bab8" rel="noreferrer noopener nofollow">[email protected]</a>",
    "id": "f5casd1e-ce6e-4c15-a36d-a710b4ca77c2"
}

有什么方法可以从我的 AD 中获取用户列表及其电话号码吗?我还尝试使用如下过滤器通过电话号码获取用户 https://graph.microsoft.com/v1.0/users?$filter=identities/any(c:c/issuerAssignedId eq '+9231xxxxxxxx'和 c/issuer eq 'guardianlitedev.onmicrosoft.com') 但这返回一个空数组。请帮忙!我的最终目标是检查给定电话号码是否存在用户并返回他们的 OID。

最佳答案

我能够重现您的问题,并发现过滤器中的加号 (+) 是问题所在。通过使用标准 Url 编码对其进行编码,我发现了成功。

+ 符号转换为 %2B

https://graph.microsoft.com/v1.0/users?$filter=identities/any(c:c/issuerAssignedId eq '+9231xxxxxxxx' 和 c/issuer eq 'guardianlitedev.onmicrosoft.com ')

https://graph.microsoft.com/v1.0/users?$filter=identities/any(c:c/issuerAssignedId eq '%2B9231xxxxxxxx' 和 c/issuer eq 'guardianlitedev.onmicrosoft.com ')

关于azure - 如何使用 Microsoft Graph API 获取 Active Directory 用户的电话号码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66227436/

相关文章:

asp.net - 如何使用 Active Directory 创建具有个人用户帐户的新 .NET 应用程序?

linux - squid basic_ldap_auth 从用户名中剥离 nt 域

azure-active-directory - 如何通过 Azure 数据库和 Active Directory 密码身份验证在 ASP.NET Core 中使用 Hangfire

azure - 为什么作为订阅的共同管理员我无法编辑 Active Directory?

c# - 添加 Azure AD 身份验证时出现 CORS 错误

c# - Azure 服务总线托管 REST 服务

.net - 在 Visual Studio 中添加 Azure Key Vault 连接服务将继续显示 "Verifying that your application will have access to the key vault"

azure - 以编程方式重新启动 Azure 上的 Web/Api-App

c# - StorageAccountList 请求在本地有效,但在 dotnet 应用程序中部署时无效

c# - user.identity.name (c#) 从哪里获得它的值(value)?