通过电子邮件地址查找用户 [英] Find a User by Email Address

查看:332
本文介绍了通过电子邮件地址查找用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying find out if an email address is already taken in my Azure AD B2C directory.

var token = await this.GetTokenAsync();

var client = new HttpClient();

var id = HttpUtility.UrlEncode("adrian_mydomain.com#EXT#@xxxxxxxxx.onmicrosoft.com");
////var id = HttpUtility.UrlEncode("adrian@mydomain.com"); // 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();

我对电子邮件地址进行编码的方式与获得所有用户时看到的电子邮件地址编码方式相同.如果可以通过电子邮件地址查询,我感觉很亲密.

I'm encoding my email address in the same way that I see my email address encoded when I get all users. I have a feeling I'm close, if it is even possible to query by email address.

当前我尝试过的所有操作都返回400或404.有人知道是否可以通过电子邮件地址(登录名)查询吗?

Currently all the things I've tried either return a 400 or a 404. Does anyone know if there is a way to query by email address (sign in name)?

编辑

在类似的主题上,我也尝试通过查询将用户密码更改为无效.我认为如果我能使查询适用于其中一个,就可以使查询适用于另一个.

On a similar theme, I'm also trying a query to change a user's password to no avail. I figure if I can get the query working for one, I can get it working on the other.

推荐答案

看看B2C.exe的实现,首先使它工作: https://azure.microsoft. com/nl-nl/documentation/articles/active-directory-b2c-devquickstarts-graph-dotnet/

Take a look at the B2C.exe implementation, first get that working: https://azure.microsoft.com/nl-nl/documentation/articles/active-directory-b2c-devquickstarts-graph-dotnet/

您会注意到,GUIDUPN引用了用户,而不是通过电子邮件! 电子邮件在signInNames

You will notice that the user is referenced by GUID or by UPN, not by email! Emails are in the collection signInNames

要查询电子邮件地址,您需要指定一个过滤器: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#GetUsers

To query on email address, you will need to specify a filter: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#GetUsers

从GetUsers(获取所有用户)开始,然后更新密码,最后添加过滤器.

Start with the GetUsers(to get all users), then update password and last the filter.

这篇关于通过电子邮件地址查找用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆