2017-08-02 5 views
0

私はSharepointリストにアプリケーションを購読しようとしています。通知はwebhooks経由でアプリに送信されます。ボディ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" 
} 

コールはアクセストークンを必要とするこれを行うには、あなたがにHTTP POSTリクエストを行う必要があります。

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

最後に、問題はアクセストークンであり、正しいアクセストークンを取得できました。これを行うには2通りの方法があり、これらの方法はシングルテナントアプリケーションにも使用できます。

方法1:Azureのクレデンシャル(のみアプリ認証情報)

ステップ1を送信せずに2つのステップは:確認コードを求めます。 この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" 
関連する問題