Azure AD B2C .Net SDK - 通过电子邮件检索用户

Azure AD B2C .Net SDK - Retrieve User by Email

我正在尝试使用 C# .NET SDK and the filter described in 在我们的 Azure AD B2C 租户上通过登录电子邮件查找用户,如下所示:

        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];
        }

我遇到错误:

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

其中 this.UserSelectValue 是 属性 选择列表,如 "id,givenName..."。我已经确认这不是问题,因为我们有一个类似的工作方法,通过扩展名 属性 查找用户;唯一的区别是 .Filter() 参数。

我怎样才能完成这项工作?谢谢。

user resource type 中没有 signInNames 属性。这就是您收到此错误的原因。

你应该使用 .Filter("identities/any(c:c/issuerAssignedId eq '{email}' and c/issuer eq '{email}')").

详见官方样本here