adal.js および jQuery (OAuth 暗黙的フロー) を使用して JavaScript を介して Office365 API に統合しようとしていますが、ユーザーのカレンダー イベントを作成しようとすると問題が発生します。電子メールとカレンダー イベントを取得する場合、既存のコードは正常に動作しますが、カレンダー イベントを作成しようとすると、常に「403 - 許可されていません」という応答が返されます。
コードはhttp://oauth.idippedut.dk/oauth.htmlで公開され、機能しています。https://outlook.office.com/api/v2.0/me/eventsで Office 365 API エンドポイントにアクセスしています。
Office365/Azure テナント Active Directory のアプリに対する "委任されたアクセス許可" の構成は次のとおりです。
Office365/Azure テナント Active Directory のアプリの「アプリケーションのアクセス許可」の構成は次のとおりです。
jQuery リクエストは次のとおりです。
var event = {
"Subject": "Discuss the Calendar REST API",
"Body": {
"ContentType": "HTML",
"Content": "I think it will meet our requirements!"
},
"Start": {
"DateTime": "2016-01-21T18:00:00",
"TimeZone": "Pacific Standard Time"
},
"End": {
"DateTime": "2016-01-21T19:00:00",
"TimeZone": "Pacific Standard Time"
},
"Attendees": [
{
"EmailAddress": {
"Address": "jesper@lundstocholm.dk",
"Name": "Janet Schorr"
},
"Type": "Required"
}
]
};
// Create calendar events
jQuery.ajax({
type: 'POST',
url: postCalenderEndpoint,
data: JSON.stringify(event),
contentType: "application/json",
headers: {
'Accept': 'application/json',
'Authorization': 'Bearer ' + token,
},
}).done(function (data) {
//alert(JSON.stringify(data));
}).fail(function (err) {
jQuery("#loginMessage").text('Error calling REST endpoint: ' + err.statusText + '\n' + err.responseText);
});
jQueryの構成は次のとおりです。
var resource = 'https://outlook.office.com';
var postCalenderEndpoint = 'https://outlook.office.com/api/v2.0/me/events';
var clientID = '28a707a5-0f11-4d93-8b88-6a918544da14';
var tenantName = '365projectum.onmicrosoft.com';
var authContext = new AuthenticationContext({
instance: 'https://login.microsoftonline.com/',
tenant: tenantName,
clientId: clientID,
postLogoutRedirectUri: window.location.origin,
cacheLocation: 'localStorage'
});
結果として得られる HTTP リクエストは次のとおりです。
Host: outlook.office.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0
Accept: application/json
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Content-Type: application/json; charset=UTF-8
Authorization: Bearer <my token>
Referer: http://oauth.idippedut.dk/oauth.html
Content-Length: 386
Origin: http://oauth.idippedut.dk
Connection: keep-alive
{"Subject":"Discuss the Calendar REST API","Body":{"ContentType":"HTML","Content":"I think it will meet our requirements!"},"Start":{"DateTime":"2016-01-21T18:00:00","TimeZone":"Pacific Standard Time"},"End":{"DateTime":"2016-01-21T19:00:00","TimeZone":"Pacific Standard Time"},"Attendees":[{"EmailAddress":{"Address":"jesper@lundstocholm.dk","Name":"Janet Schorr"},"Type":"Required"}]}
すべてが正しく設定されているはずなのに、なぜ 403 が表示されるのか、本当に困惑しています。
どんな助けでも大歓迎です:-)
/ジェスパー