請參閱底部的編輯。Office 365日曆API使用EWS和OAuth 2
我正在嘗試使用EWS(而不是託管API)使用Office 365 API來創建/刪除/更新用戶日曆上的事件。
到目前爲止,我已經成功地使用了基本身份驗證來驗證我的SOAP請求會起作用。我現在試圖用OAuth 2替換基本身份驗證。我需要使用客戶端憑證流程。
下面是我遵循的步驟:
提供的管理同意申請。我在瀏覽器中啓動了以下URL,並使用管理員帳戶提供了許可。
https://login.microsoftonline.com/common/oauth2/authorize? response_type=code+id_token& scope=openid& client_id=[Client ID]& redirect_uri=http://localhost/myapp/permissions& resource=https://outlook.office.com& prompt=admin_consent& response_mode=form_post& nonce=1234
在授予同意,我從響應檢索的
id_token
,以及使用JWT.io解碼它。從有效載荷中,我記錄了tid
。接着我發送以下請求中檢索接入令牌:
POST https://login.microsoftonline.com/[TID]/oauth2/token HTTP/1.1 cache-control: no-cache Content-Type: application/x-www-form-urlencoded Accept: */* Host: login.microsoftonline.com accept-encoding: gzip, deflate Connection: close client_id=[CLIENT ID]& client_secret=[CLIENT SECRET]& grant_type=client_credentials& resource=https%3A%2F%2Foutlook.office.com
使用訪問令牌,我發出同樣的請求我一樣使用基本認證,除我取代了基本認證報頭與
Authorization: Bearer [Access Token]
我收到以下錯誤(403 Forbidden
): The token contains not enough scope to make this call.
我需要做些什麼來解決這個錯誤?
編輯1:我加入了Use Exchange Web Services with full access to all mailboxes
應用程序的權限,併發送SOAP消息現在將導致一個500 Internal Server Error
...