【问题标题】:Azure AD B2C .Net SDK - Retrieve User by EmailAzure AD B2C .Net SDK - 通过电子邮件检索用户
【发布时间】:2020-04-28 18:59:55
【问题描述】:

我正在尝试使用C# .NET SDKthis answer 中描述的过滤器在我们的 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() 参数。

我怎样才能做到这一点?谢谢。

【问题讨论】:

    标签: c# .net-core azure-active-directory azure-ad-b2c azure-ad-graph-api


    【解决方案1】:

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

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

    详见官方示例here

    【讨论】:

    • 成功了! MS,如果您正在阅读...我遇到了这个问题的至少三种不同的变体。当前的正确方法应该在 B2C SDK 文档中更容易发现。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-18
    • 1970-01-01
    • 1970-01-01
    • 2022-11-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多