Azure Graph API 按数组值筛选

Azure Graph API Filter by array value

我正在尝试对我的 Azure B2C Active Directory 用户执行查询。

到目前为止,以下查询一切正常:

https://graph.windows.net/myTentant/users?$filter=
startswith(displayName,'test')%20
or%20startswith(givenName,'test')%20
or%20startswith(surname,'test')%20
or%20startswith(mail,'test')%20
or%20startswith(userPrincipalName,'test')
&api-version=1.6

关于这个的事情是,这个属性只是像这样的简单值:

"displayName: "testValue",
"givenName": "testValue",
"displayName: "testValue",
"surname": "testValue",
"mail: "testValue",
"userPrincipalName": "testValue",

在我的例子中,我需要再使用一个语句,我需要检查一个数组是否像其他数组一样包含 'test'。这个数组看起来像这样:

        "signInNames": [
            {
                "type": "emailAddress",
                "value": "test@mail.com"
            },                {
                "type": "emailAddress",
                "value": "test2@mail.com"
            }
        ]

我已经在官方搜索了 documentation 但是没找到.... 有什么想法吗?

理论上我们应该用下面的格式来判断值是否以"test"开头。

GET https://graph.windows.net/myorganization/users?$filter=signInNames/any(c:startswith(c/value, 'test'))

不幸的是,它会显示错误:value only supports equals-match。不支持 PrefixMatch.

并且 contains 字符串运算符目前在任何 Microsoft Graph 资源上均不受支持。所以我们也不能使用 contains

您需要使用equal来查找精确匹配数据:

GET https://graph.windows.net/myorganization/users?$filter=signInNames/any(c:c/value eq '***')

这不是解决方案。但是好像没有办法满足你的需求。

也许您可以查询所有的登录名并在您的代码中处理它们。