Microsoft Entra 報告 API 可讓您透過一組 REST API 以程式設計方式存取資料。 您可以從各種程式設計語言和工具呼叫這些 API。
本文說明如何使用 Microsoft Graph Explorer 和 Microsoft Graph PowerShell 來分析 Microsoft Entra 活動記錄。
必要條件
- 正在運作的 Microsoft Entra 租戶,具有與之相關聯的 Microsoft Entra ID P1 或 P2 授權。
- 若要同意必要的權限,您需要特殊權限角色管理員。
使用 Microsoft Graph Explorer 存取報告
設定所有必要條件後,您可以在 Microsoft Graph 中執行活動記錄查詢。 Microsoft Graph API 並非專為提取大量活動資料而設計。 使用 API 提取大量的活動資料會導致分頁和效能的問題。 如需活動記錄 Microsoft Graph 查詢的詳細資訊,請參閱活動報告 API 概觀。
選擇您的個人資料,然後選取 [修改權限]。
同意下列必要權限:
AuditLog.Read.All
Directory.Read.All
使用下列其中一個查詢來開始使用 Microsoft Graph 以存取活動記錄:
- 獲取
https://graph.microsoft.com/v1.0/auditLogs/directoryAudits
- 獲取
https://graph.microsoft.com/v1.0/auditLogs/signIns
- 獲取
https://graph.microsoft.com/v1.0/auditLogs/provisioning
- 獲取
https://graph.microsoft.com/beta/auditLogs/signUps
- 獲取
微調查詢
若要搜尋特定的活動記錄項目,請搭配其中一個可用的屬性,使用 $filter 和 createdDateTime 查詢參數。 下列某些查詢會使用 beta
端點。 Beta 端點可能會變更,不建議用於實際執行環境。
範例登入查詢
嘗試使用下列查詢進行登入活動:
對於發生 [條件式存取] 失敗的登入嘗試:
- 獲取
https://graph.microsoft.com/v1.0/auditLogs/signIns?$filter=conditionalAccessStatus eq 'failure'
- 請考慮使用日期篩選條件,讓要求不會逾時。
- 獲取
若要在特定時間範圍內尋找特定應用程式的登入:
- 獲取
https://graph.microsoft.com/v1.0/auditLogs/signIns?$filter=(createdDateTime ge 2024-01-13T14:13:32Z and createdDateTime le 2024-01-14T17:43:26Z) and appId eq 'APP ID'
- 獲取
對於非互動式登入,請遵循以下步驟:
- 獲取
https://graph.microsoft.com/beta/auditLogs/signIns?$filter=(createdDateTime ge 2024-01-13T14:13:32Z and createdDateTime le 2024-01-14T17:43:26Z) and signInEventTypes/any(t: t eq 'nonInteractiveUser')
- 獲取
對於服務主體登入:
- 獲取
https://graph.microsoft.com/beta/auditLogs/signIns?$filter=(createdDateTime ge 2024-01-13T14:13:32Z and createdDateTime le 2024-01-14T17:43:26Z) and signInEventTypes/any(t: t eq 'servicePrincipal')
- 獲取
對於受控識別登入:
- 獲取
https://graph.microsoft.com/beta/auditLogs/signIns?$filter=(createdDateTime ge 2024-01-13T14:13:32Z and createdDateTime le 2024-01-14T17:43:26Z) and signInEventTypes/any(t: t eq 'managedIdentity')
- 獲取
若要取得使用者的驗證方法:
- 獲取
https://graph.microsoft.com/beta/users/{userObjectId}/authentication/methods
- 需要
UserAuthenticationMethod.Read.All
權限
- 獲取
若要檢視使用者註冊詳細資料報告:
- 獲取
https://graph.microsoft.com/beta/reports/authenticationMethods/userRegistrationDetails
- 需要
UserAuthenticationMethod.Read.All
權限
- 獲取
有關特定使用者的註冊詳細資料:
- 獲取
https://graph.microsoft.com/beta/reports/authenticationMethods/userRegistrationDetails/{userId}
- 需要
UserAuthenticationMethod.Read.All
權限
- 獲取
註冊查詢範例 (預覽)
請嘗試在您的外部租戶中使用下列查詢以進行註冊活動:
若要尋找在特定步驟期間失敗或中斷的註冊嘗試,例如用戶物件建立:
- 獲取
https://graph.microsoft.com/beta/auditLogs/signUps?$filter=status/errorCode ne 0 and signUpStage eq 'userCreation'
- 獲取
若要尋找在電子郵件驗證期間失敗的註冊嘗試:
- 獲取
https://graph.microsoft.com/beta/auditLogs/signUps?$filter=status/errorCode eq 1002013 and signUpStage eq 'credentialValidation'
備註
錯誤碼1002013指出註冊流程的預期(且成功)中斷。 瞭解更多資訊
- 獲取
在特定日期範圍內註冊:
- 獲取
https://graph.microsoft.com/beta/auditLogs/signUps?&$filter=(createdDateTime ge 2024-01-13T14:13:32Z and createdDateTime le 2024-01-14T17:43:26Z)
- 獲取
特定應用程式的註冊流程:
- 獲取
https://graph.microsoft.com/beta/auditLogs/signUps?$filter=appId eq 'AppId'
- 獲取
本地帳戶註冊:
- 獲取
https://graph.microsoft.com/beta/auditLogs/signUps?$filter=signUpIdentityProvider eq 'Email OTP' or signUpIdentityProvider eq 'Email Password'
- 獲取
針對社群帳戶註冊(本例以 Google 為例):
- 獲取
https://graph.microsoft.com/beta/auditLogs/signUps?$filter=signUpIdentityProvider eq ‘Google'
- 獲取
若要查看特定使用者的條目,例如
user@contoso.com
:- 獲取
https://graph.microsoft.com/beta/auditLogs/signUps?$filter=signUpIdentity/signUpIdentifier eq 'user@contoso.com'
- 獲取
若要尋找符合特定相互關聯識別碼的專案:
- 獲取
https://graph.microsoft.com/beta/auditLogs/signUps?$filter=correlationId eq 'CorrelationId'
- 獲取
若要使用關聯 ID 尋找對應至特定註冊的登入記錄項目:
- 獲取
https://graph.microsoft.com/v1.0/auditLogs/signIns?$filter=correlationId eq 'CorrelationId'
- 獲取
相關的 API
一旦您熟悉標準登入和稽核記錄,請嘗試探索下列其他 API:
使用 Microsoft Graph PowerShell 來存取報告
您可以使用 PowerShell 來存取 Microsoft Entra 報告 API。 如需詳細資訊,請參閱 Microsoft Graph PowerShell 概觀。
Microsoft Graph PowerShell 指令集 (cmdlets)
-
稽核記錄:
Get-MgAuditLogDirectoryAudit
-
登入記錄:
Get-MgAuditLogSignIn
-
佈署記錄:
Get-MgAuditLogProvisioning
- 探索報告相關 Microsoft Graph PowerShell Cmdlet 的完整清單。
常見錯誤
錯誤:租用戶都不是 B2C 或租用戶沒有進階授權:存取登入報告需要 Microsoft Entra ID P1 或 P2 授權。 若在存取登入時看到這個錯誤訊息,請確定您的租用戶已獲得 Microsoft Entra ID P1 授權。
錯誤:使用者不在允許的角色中:若在嘗試使用 API 存取稽核記錄或登入時,看到這個錯誤訊息,請確定您的帳戶屬於 Microsoft Entra 租用戶中的安全性讀取者或報告讀取者角色。
錯誤:應用程式遺漏 Microsoft Entra ID 'Read directory data' 或 'Read all audit log data' 權限:應用程式必須具有 AuditLog.Read.All
或 Directory.Read.All
權限,才能使用 Microsoft Graph 來存取活動記錄。