我已关注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 实现仅限于为两者 issuerAssignedId
和 issuer
提供精确值>.
我实现的解决方法是将 issuerAssignedId
保留在附加扩展属性中。如果您使用自定义策略,这相对容易实现。但如果您使用用户流,则很容易出错,因为没有直接的方法将此值记录为附加属性。基本上,您必须不断在 MS Graph 中查询 (delta at best!) users并根据 IssuerAssignedId 更新自定义属性。
关于.net - AAD B2C : Search Users by PrincipalName,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65830662/