"Updated" Microsoft Graph 已删除用户的通知类型

"Updated" notification type for Microsoft Graph deleted user

从 Active Directory (AD) 删除用户后收到此通知(使用 Microsoft Graph 订阅):

{
  "value": [
{
  "changeType": "updated",
  "clientState": null,
  "resource": "Users/{user-id}",
  "resourceData": {
    "@odata.type": "#Microsoft.Graph.User",
    "@odata.id": "Users/{user-id}",
    "id": "{user-id}",
    "organizationId": "{organisation-id}",
    "sequenceNumber": hidden
  },
  "subscriptionExpirationDateTime": "2019-01-17T12:48:43.7825578+00:00",
  "subscriptionId": "hidden",
  "tenantId": "hidden"
}
]
}

接下来尝试从 Microsoft Graph 获取此用户

/GET https://graph.microsoft.com/v1.0/users/{user-id}

得到了

{
  "error": {
  "code": "Request_ResourceNotFound",
  "message": "Resource '{user-id}' does not exist or one of its queried reference-property objects are not present.",
  "innerError": {
  "request-id": "{user-id}",
  "date": "2019-01-15T13:41:49"
   }
  }
}

如果用户不存在,为什么通知带有 changeType = "updated"?

当用户从目录中删除时,他们是 "soft-deleted"(这意味着对象仍然可以访问 - 见下文,并恢复)。这种类型的更改被建模为 'update'。我们计划在未来的版本中对此进行改进。

资源将最终被硬删除(通常在 30 天后),当发生这种情况时,您会看到 'deleted' 通知。

无法使用 users/id 访问软删除的用户 - 因此出现了您看到的错误。

但是,可以使用特殊的 deletedItems API:

访问 Azure AD 中的软删除资源

https://docs.microsoft.com/en-us/graph/api/directory-deleteditems-get?view=graph-rest-1.0