Azure B2C check user exist or not?

依然范特西╮ 提交于 2021-02-16 14:20:14

问题


I am using Azure B2C, followed by the article

https://docs.microsoft.com/en-us/azure/active-directory-b2c/active-directory-b2c-devquickstarts-graph-dotnet

User is added successfully. But the issue is how to check the user exist or not with a user name, when I creating a new user?


回答1:


You can find users by their email address or their user name using the signInNames filter.

For an email address:

`GET https://graph.windows.net/myorganization/users?$filter=signInNames/any(x:x/value eq 'someone@somewhere.com')&api-version=1.6`

For a user name:

`https://graph.windows.net/myorganization/users?$filter=signInNames/any(x:x/value eq 'someone')&api-version=1.6`



回答2:


Programmatically, to check the user with the email address already exist. here is a solution using C# and Graph client library.

private async Task<User> CheckUserAlreadyExistAsync(string email, CancellationToken ct)
    {
        var filter = $"identities/any(c:c/issuerAssignedId eq '{email}' and c/issuer eq '{email}')";

        var request = _graphServiceClient.Users.Request()
            .Filter(filter)
            .Select(userSelectQuery)
            .Expand(e => e.AppRoleAssignments);

        var userCollectionPage = await request.GetAsync(ct).ConfigureAwait(false);

        return userCollectionPage.FirstOrDefault();
    }


来源:https://stackoverflow.com/questions/52288877/azure-b2c-check-user-exist-or-not

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!