Microsoft Graph Api 获取 PasswordCreds 并按 endDateTime 排序

问题描述 投票:0回答:1

我目前正在使用 Microsoft GraphApi,并且已经得到了我大部分想要的结果,但我似乎无法按

passwordCredentials/endDateTime
对它们进行排序。现在根据我的理解,这是一个多级调用,因为下面的 Json 查询显示日期嵌套在
passwordCredentials
对象中。如果可能的话,即时消息会尝试先获取即将过期的应用程序。

微软资源管理器工具

这是查询:

https://graph.microsoft.com/v1.0/applications?$select=id,keyCredentials,passwordCredentials

当我

时得到的json示例
{
"value": [
    {
        "id": "00000000-0000-0000-0000-00000001",
        "displayName": "account name 1",
        "passwordCredentials": [
            {
                "customKeyIdentifier": null,
                "displayName": "Testing 1",
                "endDateTime": "2023-11-15T20:55:22.571Z",
                "hint": "akW",
                "keyId": "00000000-0000-0000-0000-00000001",
                "secretText": null,
                "startDateTime": "2023-05-19T19:55:22.571Z"
            },
            {
                "customKeyIdentifier": null,
                "displayName": null,
                "endDateTime": "2119-05-09T16:43:05.4628335Z",
                "hint": "P49",
                "keyId": "00000000-0000-0000-0000-00000002",
                "secretText": null,
                "startDateTime": "2019-05-09T16:43:05.4628335Z"
            }
        ]
    },
    {
        "id": "00000000-0000-0000-0000-00000002",
        "displayName": "account name 2",
        "passwordCredentials": [
            {
                "customKeyIdentifier": null,
                "displayName": "Testing 2",
                "endDateTime": "2025-01-29T22:25:40.768Z",
                "hint": "9Oz",
                "keyId": "00000000-0000-0000-0000-00000002",
                "secretText": null,
                "startDateTime": "2023-01-30T22:25:40.768Z"
            }
        ]
    }
 ]
}

我想我可以在最后添加

&$orderby=
,看看我是否可以得到一些东西,它给了我这个回应。

https://graph.microsoft.com/v1.0/applications?$select=id,keyCredentials,passwordCredentials&$orderby=displayName

回复:

{
"error": {
    "code": "Request_UnsupportedQuery",
    "message": "Sorting not supported for 'Application'.",
    "innerError": {
        "date": "2024-04-17T18:51:22",
        "request-id": "f31287e1-0105-463e-8611-b80c495ae67c",
        "client-request-id": "edcaa30c-6ee2-c876-b331-c7570345a5d1"
    }
  }
}
c# json asp.net-mvc microsoft-graph-api
1个回答
0
投票

Graph API 仅支持对单个值进行排序,

passwordCredentials
是一个集合。

您必须在客户端上应用排序,或者您可以找到很多 PowerShell 脚本如何查找过期的客户端机密。

https://www.joeyverlinden.com/find-expiring-client-secrets-using-graph-api-and-powershell/

为了能够按单个值对应用程序进行排序(如

displayName
),您需要添加
$count=true
查询参数并包含请求标头
ConsistencyLevel
和值
eventual

GET https://graph.microsoft.com/v1.0/applications?$select=id,keyCredentials,passwordCredentials&$orderby=displayName&$count=true
© www.soinside.com 2019 - 2024. All rights reserved.