如何根据自定义用户属性过滤 azure b2c 中的用户?

问题描述 投票:0回答:1

我创建了一个自定义用户属性 customerId 在Azure B2C用户属性中,用来区分特定客户的用户。我可以使用 图形API 和.net B2C sdk,并使用这个git hub设置customerId。样品

我的问题是我不能用customerId过滤客户。我的代码如下

    public static async Task<List<User>> GetAllB2CUsersByCustomerId(GraphServiceClient graphClient, int customerId)
    {

        try
        {
            // Get users by customerId
            var result = await graphClient.Users
                .Request()
                .Filter($"additionalData/any(c:c/key eq 'extension_b2cApplicationIdWithoutDashes_customerId' and c/value eq '{customerId}')")
                .Select(e => new
                {
                    e.DisplayName,
                    e.Id,
                    e.Identities
                })
                .GetAsync();

            if (result != null)
            {
                return result.ToList();
            }
        }
        catch (Exception ex)
        {
            // catch exception

        }
        return null;
    }

当代码运行时,我得到以下异常

Code: BadRequest
Message: Filter not supported.
Inner error:
    AdditionalData:
    request-id: 21d0c9d3-7d6a-4c97-9066-c99f678aec54
    date: 2020-06-10T15:59:37
ClientRequestId: 21d0c9d3-7d6a-4c97-9066-c99f678aec54
azure-ad-b2c azure-ad-graph-api
1个回答
0
投票

当对身份进行过滤时,你必须同时提供发行人和发行人指定的ID。文件

.Filter("identities/any(c:c/issuerAssignedId eq '[email protected]' and c/issuer eq 'contoso.onmicrosoft.com')")

0
投票

如果对某人有帮助的话,以下是对自定义属性的语法过滤方法。

public static async Task<List<User>> GetAllB2CUsersByCustomerId(GraphServiceClient graphClient, int customerId)
{

    try
    {
        // Get users by customerId
        var result = await graphClient.Users
            .Request()
            .Filter($"extension_b2cApplicationIdWithoutDashes_customerId eq {customerId}")
            .Select(e => new
            {
                e.DisplayName,
                e.Id,
                e.Identities
            })
            .GetAsync();

        if (result != null)
        {
            return result.ToList();
        }
    }
    catch (Exception ex)
    {
        // catch exception

    }
    return null;
}
© www.soinside.com 2019 - 2024. All rights reserved.