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

How to filter users in azure b2c based on custom user attribute?

我在 Azure B2C 用户属性中创建了自定义用户属性 customerId 以区分特定客户的用户。我可以使用 Graph API and .net B2C sdk and set the customerId using this git hub sample

创建用户

我遇到的问题是无法按 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

过滤身份时,您必须同时提供发行者和 issuerAssignedId.Please 参考此 document

.Filter("identities/any(c:c/issuerAssignedId eq 'j.smith@yahoo.com' and c/issuer eq 'contoso.onmicrosoft.com')")

如果对某人有帮助,以下语法会过滤自定义属性

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