现在 Microsoft 365 / Office 365 A1 A1P E3 MSDN 添加 API 后,应用密钥时间最多是两年,以防万一,我们当然希望应用密钥时间越长越好,其实官方给出了相应的方法
请看官方文档:
https://docs.microsoft.com/zh-CN/graph/api/overview?view=graph-rest-1.0
进入:
https://developer.microsoft.com/zh-cn/graph/graph-explorer
登录全局管理员账号
在【修改权限】中同意授权
请求头修改为【POST】
请求地址
# 将 0cbb7e9f-23fc-4e4c-8fc8-1008611NB 修改为你应用程序中的【对象 ID】 https://graph.microsoft.com/v1.0/applications/{0cbb7e9f-23fc-4e4c-8fc8-1008611NB}/addPassword
请求正文
# displayName 为密钥名称,可随意设置 # endDateTime 为密钥到期时间,可随意设置 { "passwordCredential": { "displayName": "microsoft", "endDateTime": "2299-05-07T00:00:00Z" } }
设置好后,点击【运行查询】
返回结果如下
# keyId 为 Secret ID # secretText 为新的应用密钥,请一定要记牢,请一定要记牢,请一定要记牢 { "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#microsoft.graph.passwordCredential", "customKeyIdentifier": null, "displayName": "microsoft", "endDateTime": "2299-05-07T00:00:00Z", "hint": "qx7", "keyId": "9a3a899c-5838-431c-9402-cbcd111f44cf", "secretText": "qx79tX~K8c43k46YkT5c-EiuQ_kcP7JO-b", "startDateTime": "2021-05-13T12:38:46.2465188Z" }
利用微软官方工具 Graph Explorer 添加 / 修改 API 应用密钥时间成功
查看评论 (3)
两个权限都已授权,用管理员设置子号的密钥期限,提示错误
{
"error": {
"code": "Request_ResourceNotFound",
"message": "Resource '{7d02a8ad-****-4b4d-9259-61f4a817****}' does not exist or one of its queried reference-property objects are not present.",
"innerError": {
"date": "2021-05-14T06:27:06",
"request-id": "ecded677-****-45fa-9364-6d5e58f0****",
"client-request-id": "2af91680-****-2ce2-1f0a-6b1b7ba8****
}
}
}
用全局管理员试试,是对象 ID,不是用户ID哦
用管理员账号设置子号密钥期限,提示错误
{
"error": {
"code": "Request_ResourceNotFound",
"message": "Resource '{7d02a8ad-ba69-4b4d-9259-61f4a8172cd5}' does not exist or one of its queried reference-property objects are not present.",
"innerError": {
"date": "2021-05-14T06:27:06",
"request-id": "ecded677-1cea-45fa-9364-6d5e58f04578",
"client-request-id": "2af91680-15c0-2ce2-1f0a-6b1b7ba824fe"
}
}
}