简体   繁体   中英

Azure AD B2C .Net SDK - Retrieve User by Email

I'm trying to look up a user by sign-in email on our Azure AD B2C Tenant using the C# .NET SDK and the filter described in this answer , like so:

        private async Task<User> GetB2CUserByEmail(string email)
        {
            IGraphServiceUsersCollectionPage collectionPage = await this.GraphServiceClient.Users
                .Request()
                .Filter($"signInNames/any(c:c/value eq '{email}')")
                .Select(this.UserSelectValue)
                .GetAsync();

            if (collectionPage == null || collectionPage.Count == 0)
            {
                return null;
            }

            return collectionPage[0];
        }

I'm getting the error:

 Microsoft.Graph.ServiceException : Code: BadRequest
    Message: Filter not supported.

Where this.UserSelectValue is a property selection list like "id,givenName..." . I've confirmed that's not the issue because we have a similar working method that looks up a user by an extension property; the only difference is the .Filter() parameter.

How can I make this work? Thanks.

There is not a signInNames property in user resource type . That's the reason you get this error.

You should use .Filter("identities/any(c:c/issuerAssignedId eq '{email}' and c/issuer eq '{email}')") .

See details from the official sample here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM