gpt4 book ai didi

c# - 通过电子邮件地址查找用户

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

我正在尝试查明电子邮件地址是否已在我的 Azure AD B2C 目录中使用。

var token = await this.GetTokenAsync();

var client = new HttpClient();

var id = HttpUtility.UrlEncode("adrian_mydomain.com#EXT#@xxxxxxxxx.onmicrosoft.com");
////var id = HttpUtility.UrlEncode("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="92f3f6e0fbf3fcd2ffebf6fdfff3fbfcbcf1fdff" rel="noreferrer noopener nofollow">[email protected]</a>"); // This also fails.
////var id = HttpUtility.UrlEncode("adrian_mydomain.com#EXT#"); // This also fails.
////var id = "xxxx-xxxx-xxxxxxxx-xxxxxxxxxx"; // This also fails (user object id).

var resource = $"{this.graphConfig.GraphUri}/{this.graphConfig.Tenant}/users/{id}?api-version=1.6";
//// This line below works, it returns all the users, so I do know the token is good and the resource URI is valid, etc.
////var resource = $"{this.graphConfig.GraphUri}/{this.graphConfig.Tenant}/users?api-version=1.6";

var request = new HttpRequestMessage(HttpMethod.Get, resource);
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);

var response = await client.SendAsync(request);
var content = await response.Content.ReadAsStringAsync();

我对我的电子邮件地址进行编码的方式与我在获取所有用户时看到的对我的电子邮件地址进行编码的方式相同。如果甚至可以通过电子邮件地址进行查询,我感觉我已经很接近了。

目前我尝试过的所有方法都返回 400 或 404。有谁知道是否有办法通过电子邮件地址(登录名)进行查询?

编辑

在类似的主题上,我也尝试查询来更改用户的密码,但无济于事。我想如果我能让查询对其中一个起作用,我就可以让它对另一个起作用。

最佳答案

由于是odata,所以可以使用odata语法进行查询。 Odata 语法 here

var queryString = HttpUtility.ParseQueryString(string.Empty);
queryString["api-version"] = "1.6";
queryString["$filter"] = "signInNames/any(x:x/value eq '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1c6c7d6970795c68796f68327572" rel="noreferrer noopener nofollow">[email protected]</a>')";

string url = "https://graph.windows.net/" + tenant + "/users"+ "?" + queryString;

$filter 成功了

queryString["$filter"] = "signInNames/any(x:x/value eq ' [email protected] ')";

关于c# - 通过电子邮件地址查找用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37327823/

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