2017-08-02 78 views
0

我試圖訂閱應用程序到Sharepoint列表。通知將通過webhook發送到應用程序。要做到這一點,你必須做出一個HTTP POST請求:Sharepoint webhooks:訂閱列表

https://{your-account}.sharepoint.com/_api/web/lists('{list-guid}')/subscriptions 

身體:

{ 
    "resource": "{{ URL of the resource Id }}", 
    "notificationUrl" : "{{ URL of the endpoint that will process the webhooks }}", 
    "expirationDateTime" : "2017-09-27T00:00:00+00" 
} 

呼叫需要一個訪問令牌。我通過這種方式獲得了curl令牌:

curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "client_id={{ Id of the application registered on Azure Active Directory }}&client_secret={{ Key added on Azure for the app }}&grant_type=client_credentials&resource=https%3A%2F%2F{{ My account }}.sharepoint.com" "https://login.microsoftonline.com/{{ Azure account tenant id}}/oauth2/token" 

這將返回一個包含在POST請求中的標頭的標記。不幸的是,此請求失敗,錯誤代碼401正文:

{ 
    "error_description" : "The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework SDK documentation and inspect the server trace logs." 
} 

我覺得這個問題是不是道理,我們嘗試過很多次才停止投擲無效令牌數據相關的錯誤。

有沒有辦法來調試這個錯誤?有什麼建議麼?

回答

0

最後,問題是訪問令牌,我們能夠得到正確的訪問令牌。有兩種方法可以做到這一點,這些方法適用於單租戶應用程序。

方法1:兩個步驟而不發送天青憑證(唯一的應用程序憑證)

步驟1:申請驗證碼。 訪問此URL。它會將您重定向到在查詢字符串中傳遞的redirect_uri,並且重定向的查詢字符串將包含將用於請求令牌的代碼。

https://login.microsoftonline.com/{{ Tenant id }}/oauth2/authorize?client_id={{ Application id }}&response_type=code&redirect_uri={{ URI of the application }}&response_mode=query&resource={{ Resource that you want to access}}&state=12345 

資源例如:HTTPS%3A%2F%2Fyouraccount.sharepoint.com

步驟2:請求令牌

curl -X POST -H "content-type: application/x-www-form-urlencoded" -d "grant_type=authorization_code&client_id={{ Application code }}&code={{ The code received in the last request }}&redirect_uri={{ Same redirect URI }}&resource={{ Same resource}}&client_secret={{ Application key }}" https://login.microsoftonline.com/{{ Tenant id }}/oauth2/token 

方法2:一步,在發送天青憑證

curl -i -X POST -d "grant_type=password&resource={{ Resource id }}&client_id={{ App id }}&username={{ Azure username }}&password={{ Azure password }}" "https://login.windows.net/{{ Tenant id }}/oauth2/token"