Azure ad b2c 如何根据自定义用户属性筛选azure b2c中的用户?
我在Azure B2C用户属性中创建了一个自定义用户属性Azure ad b2c 如何根据自定义用户属性筛选azure b2c中的用户?,azure-ad-b2c,azure-ad-graph-api,Azure Ad B2c,Azure Ad Graph Api,我在Azure B2C用户属性中创建了一个自定义用户属性customerId,以区分特定客户的用户。我可以使用和.net B2C sdk创建用户,并使用此git hub设置customerId 我的问题是我无法按customerId筛选客户。我的代码如下所示 public static async Task<List<User>> GetAllB2CUsersByCustomerId(GraphServiceClient graphClient, int cust
customerId
,以区分特定客户的用户。我可以使用和.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;
}
在对身份进行筛选时,您必须同时提供issuer和ISSUERASIGNEDID。请参阅此
如果它对某人有帮助,下面的语法会对自定义属性进行过滤
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;
}
公共静态异步任务GetAllB2cuserByCustomerId(GraphServiceClient graphClient,int customerId)
{
尝试
{
//通过customerId获取用户
var result=wait graphClient.Users
.Request()
.Filter($“扩展名\u b2capapplicationidwithout破折号\u customerId eq{customerId}”)
.选择(e=>new
{
e、 显示名称,
e、 身份证,
e、 身份
})
.GetAsync();
如果(结果!=null)
{
返回result.ToList();
}
}
捕获(例外情况除外)
{
//捕获异常
}
返回null;
}
我已尝试将发卡机构添加到筛选器中,但没有任何区别。谢谢您的回答。这解决了我的问题。此外,我必须确保自定义属性不以大写字母开头。As“CustomerId”如果按小写字母过滤,则会引发异常,如果按大写字母过滤,则不会返回任何结果。将其定义为“customerId”修复了该问题。
.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;
}