.net - AAD B2C : Search Users by PrincipalName

标签 .net azure azure-active-directory microsoft-graph-api microsoft-graph-sdks

我已关注documentation通过登录名查找注册用户。

该示例显示以下代码,用于返回具有登录名 <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fd97d38e90948995bd849c959292d39e9290" rel="noreferrer noopener nofollow">[email protected]</a> 的任何用户:

var users = await graphClient.Users
    .Request()
    .Filter("identities/any(c:c/issuerAssignedId eq '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f59fdb86989c819db58c949d9a9adb969a98" rel="noreferrer noopener nofollow">[email protected]</a>' and c/issuer eq 'contoso.onmicrosoft.com')")
    .GetAsync();

现在我正在尝试实现一个搜索,该搜索应该搜索用户而无需输入完整的 signInName 。由于过滤器似乎是 OData,我尝试使用 contains 来增强它方法:

var users = await graphClient.Users
    .Request()
    .Filter($"identities/any(c:contains(c/issuerAssignedId,'j.smith') and c/issuer eq 'contoso.onmicrosoft.com') ")
    .Top(5)
    .GetAsync();

现在,当我运行这个新查询时,我收到以下错误:

Status Code: BadRequest
Microsoft.Graph.ServiceException: Code: Request_BadRequest
Message: An unknown function with name 'contains' was found. This may also be a key lookup on a navigation property, which is not allowed.

我是否有拼写错误,或者是 contains不允许?我不认为issuerAssignedId是查找或导航属性。由于我使用 Azure AD B2C,$search函数也无法根据相同的文档页面工作,所以我现在陷入困境。

在 Azure AD B2C 中搜索用户的方式是什么?

编辑

我发现另外两篇 StackOverflow 文章讨论了这个问题,但它们已经很老了。在 one of them ,一位 Microsoft 员工指出,可以使用 startswith运算符。

我尝试过像这样实现它,但它也会引发错误。

.Filter($"identities/any(a:startswith(a/issuerAssignedId,'{username}') and a/issuer eq '{issuer}') ")
Status Code: BadRequest
Microsoft.Graph.ServiceException: Code: Request_BadRequest
Message: Unsupported property or property value or combination of property and operation occured

更多来源:

最佳答案

请注意,contains 运算符当前为 not supported on any MS Graph queries ,有一个使用 startsWith 的解决方法。

用于查找 identities 属性的 Microsoft Graph 实现仅限于为两者 issuerAssignedIdissuer 提供精确值>.

我实现的解决方法是将 issuerAssignedId 保留在附加扩展属性中。如果您使用自定义策略,这相对容易实现。但如果您使用用户流,则很容易出错,因为没有直接的方法将此值记录为附加属性。基本上,您必须不断在 MS Graph 中查询 (delta at best!) users并根据 IssuerAssignedId 更新自定义属性。

关于.net - AAD B2C : Search Users by PrincipalName,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65830662/

相关文章:

C# HttpClient 上传速度慢

c# - 过滤 XML 文档部分的有效方法

c# - Visual Web Developer 2010 Express - 创建面向 .NET 2.0 的 ASP.NET 网站

asp.net-mvc - 如何构造一个基地址为当前部署域的Uri?

azure - 通过WAF的Blob存储连接数据流

azure - 以编程方式将用户作为组所有者添加到 Azure AD 中的组

c# - 如何在 Surface 4 Pro 中禁用 WPF 平板电脑支持?

azure - 使用电子邮件地址作为用户名邀请外部用户加入 Azure B2C

Spring 云微服务的 Azure AD 登录/注销实现

azure - 如何在广告 B2C 自定义政策中添加类型 "StringCollection"的声明