gpt4 book ai didi

c# - 如何使用 Microsoft Graph sdk 通过电子邮件地址从 Active Directory 获取用户信息

转载 作者:行者123 更新时间:2023-12-02 07:59:59 25 4
gpt4 key购买 nike

我们希望使用 Microsoft Graph SDK 从 Azure Active Directory 检索用户信息。

给出了有效的电子邮件地址,但我收到错误

Resource '[email protected]' does not exist or one of its queried reference-property objects are not present.

代码如下。可以指导一下吗?

IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder.Create(clientId).WithTenantId(tenantID).WithClientSecret(clientSecret).Build();
ClientCredentialProvider authProvider = new ClientCredentialProvider(confidentialClientApplication);
GraphServiceClient graphClient = new GraphServiceClient(authProvider);
var user = await graphClient.Users["<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d0bda9b5bdb1b9bcb1b4b4a2b5a3a390bcb9a6b5feb3bfbd" rel="noreferrer noopener nofollow">[email protected]</a>"].Request().GetAsync();

最佳答案

我可以重现您的问题。账号<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="375a4e525a565e5b56535345524444775b5e41521954585a" rel="noreferrer noopener nofollow">[email protected]</a>Guest在您的租户中,导航到门户中的 AAD -> 找到该帐户 -> 单击它并获取 Object ID ,然后使用Object ID在代码中,它会起作用。

var user = await graphClient.Users["<Object ID>"].Request().GetAsync();

或者您可以使用filter在您的情况下,让用户获得 UserPrincipalName 的格式对于 guest 用户将类似于 myemailaddress_live.com#EXT#@tenantname.onmicrosoft.com ,在使用过滤器时,我们需要对它进行URL编码,那么它将是 myemailaddress_live.com%23EXT%23%40tenantname.onmicrosoft.com ,尝试下面的代码,它在我这边有效。

var user = await graphClient.Users.Request().Filter("UserPrincipalName eq 'myemailaddress_live.com%23EXT%23%40tenantname.onmicrosoft.com'").GetAsync();

更新:

如果你想通过 UserPrincipalName 获取用户,您也可以使用如下的 url 编码。

var user = await graphClient.Users["myemailaddress_live.com%23EXT%23%40tenantname.onmicrosoft.com"].Request().GetAsync();

关于c# - 如何使用 Microsoft Graph sdk 通过电子邮件地址从 Active Directory 获取用户信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58222315/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com