[英]Sharepoint Online REST API with Azure AD v2.0 authentication
[英]How to Access Sharepoint Online API with v1 Azure AD Application and Client Credentials
我無法使用 Postman 在線對 Sharepoint 進行 API 調用。 我已經成功地對圖表 API 進行了 API 調用,所以我熟悉我認為這應該如何工作。
我已按照以下說明進行設置:
第一篇文章說它不會接受使用客戶端密碼生成的訪問令牌,但我已經生成了帶有密碼和證書的令牌,並且沒有發現任何區別。
調用任何東西時,例如:
https://<tenant>.sharepoint.com/_api/web
我得到錯誤:
{"error_description":"Exception of type 'Microsoft.IdentityModel.Tokens.AudienceUriValidationFailedException' was thrown."}
這是我使用 v1 /token 端點生成的訪問令牌示例:
{
"aud": "https://microsoft.sharepoint-df.com/",
"iss": "https://sts.windows.net/462c0b***********c3708/",
"iat": 1569243291,
"nbf": 1569243291,
"exp": 1569247191,
"aio": "42FgYDiXt***********==",
"app_displayname": "T***********n",
"appid": "00c***********2b",
"appidacr": "2",
"idp": "https://sts.windows.net/46***********708/",
"oid": "2f8a5***********684",
"roles": [
"User.ReadWrite.All",
"TermStore.Read.All",
"Sites.FullControl.All"
],
"sid": "5ab8d57***********0bc",
"sub": "2f8a5***********684",
"tid": "462c0***********708",
"uti": "aHt8d***********9AA",
"ver": "1.0"
}
該錯誤消息似乎暗示我在 /token 端點調用中的資源參數設置不正確。 我相信微軟文檔中省略了這一點,因為文檔是如此分裂。 V1 應用程序調用 SharePoint Online 的正確令牌端點調用如下所示:
Web 服務
POST https://login.microsoftonline.com/<TARGET-TENANT-ID OR NAME>/oauth2/token
參數
client_id= <Application ID from Azure Portal>
grant_type=client_credentials
resource= https://<TARGET-TENANT-NAME>.sharepoint.com
client_assertion_type= urn:ietf:params:oauth:client-assertion-type:jwt-bearer
client_assertion= <See Link Above to create assertion>
上面的鏈接省略了如何計算證書 JWT 的 x5t 值。 你可以使用這個:
echo $(openssl x509 -in certificate.pem -fingerprint -noout) | sed 's/SHA1 Fingerprint=//g' | sed 's/://g' | xxd -r -ps | base64
我從這里得到的: How to get value of "x5t" using Certificate credentials for application authentication
如果您嘗試使用客戶端密碼而不是客戶端斷言,您將獲得一個令牌,但 SharePoint 在線 REST API 將返回:
Unsupported app only token.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.