51CTO博客地址:https://blog.51cto.com/1396817
博客園博客地址:https://www.cnblogs.com/bxapollo
Microsoft Graph 是一個RESTful web API,可以通過它來訪問Microsoft 云服務器資源,注冊應用程式并獲取用戶或服務的身份驗證令牌后,可以向Microsoft Graph API請求,
默認的情況下,Deltalinks(Token)是一個用戶范圍的API,可用于類似同步的行為,比如可以獲取一個完整的權限列舉來驗證,Delta嘗試將基于權限的更改范圍限定為Caller相關的更改,如果caller的訪問權限沒有因權限更改而改變,則該項可能不會包含在增量結果中,
獲取權限的前提條件:確保遵守aca.ms/scanguidance中的建議,否則將導致獲取權限更改范圍的縮小,
獲取權限的方法:
- 對sites.fullcontrol使用使用僅適用于應用程式的身份驗證
- 所有范圍和pass header “preferred"="deltashowsharingchanges.hierarchicalsharing"
實作步驟:
1. 在AAD創建一個應用程式,并且有sites.fullcontrol等如下權限

2. 采用如下powershell腳本生成access token和delta token link:
cls
$host.Runspace.ThreadOptions = "ReuseThread"
Write-Host "STARTED at" (Get-Date).ToString() -f Green
$ClientID = "fa9737d5-5a3e-4fab-0000-000000000000"
$ClientSecret = "1JOe:M8HBBUz-0000000000000000000"
$scope= "https://graph.microsoft.com/.default"
$POSTURI = "https://login.microsoftonline.com/d6f932a7-5f74-0000-0000-000000000000/oauth2/v2.0/token"
$body = @{grant_type="client_credentials";client_id=$ClientID;client_secret=$ClientSecret;scope=$scope}
$oauth = Invoke-RestMethod -Method Post -Uri $POSTURI -Body $body $graphAccessToken = $oauth.access_token
Write-Host "Access token: $($graphAccessToken)"
$requestHeader = @{
"Authorization" = "Bearer $graphAccessToken"
"Content-Type" = "application/json"
"Prefer" = "deltashowsharingchanges,hierarchicalsharing,deltatraversepermissiongaps,deltashowremovedasdeleted"
}
$Uri = "https://graph.microsoft.com/v1.0/sites/spotenant.sharepoint.com,df6ba610-b132-0000-0000-000000000000,e0dbcdc6-0637-4246-0000-000000000000/drive/root/delta?latest"
$Result = (Invoke-RestMethod -Method Get -Headers $requestheader -Uri $Uri)
$deltaUri = $Result.'@odata.deltaLink'
Write-Host $deltaUri
Write-Host "DONE at" (Get-Date).ToString() -f Green
3. 從上面的腳本復制access token 和deltauri值輸出,并在下面的示例powershell腳本中使用它們來檢索完整的權限更改集,
cls
$host.Runspace.ThreadOptions = "ReuseThread"
Write-Host "STARTED at" (Get-Date).ToString() -f Green
$graphAccessToken = "copied from output of above sample powershell script" $requestHeader = @{
"Authorization" = "Bearer $graphAccessToken"
"Content-Type" = "application/json"
"Prefer" = "deltashowsharingchanges,hierarchicalsharing"
}
Write-Host
$deltaUri = "copied from output of above sample powershell script" #should look like sample below: https://graph.microsoft.com/v1.0/sites/spotenant.sharepoint.com,df6ba610-b132-4fc7-0000-000000000000,e0dbcdc6-0637-4246-0000-000000000000/drive/root/delta?token=MzslMjM0OyUyMzE7Mzs3NDlhZjc4NC0zOWU0LTRlOTEtYmJkNy0wNzI5MjAxNTNlMGY7NjM3MzM2NDU1MzMyNDcwMDAwOzMxOTY4OTE4MjslMjM7JTIzOyUyMzA" $deltaResult = (Invoke-RestMethod -Method Get -Headers $requestheader -Uri $deltaUri) Write-Host $deltaResult.value
Write-Host
Write-Host "DONE at" (Get-Date).ToString() -f Green
相關參考資料:
- Use the Microsoft Graph API
- Track Changes for a Drive
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/196042.html
標籤:其他
上一篇:prufer公式整理
