I'm trying to create a small client-side webapp with adal.js (currently without the angular part).
I have manged to login and get an authenticated user object. However I'm getting an invalid OAuth token from the API apparently.
The configuration I'm sending to the AuthenticationContext instance:
var config = {
instance: 'https://login.microsoftonline.com/',
tenant: 'dbaa88b3-...',
clientId: 'f81bede8-...',
postLogoutRedirectUri: window.location.href,
cacheLocation: 'localStorage',
};
Not sure if it's suppose to be the tenant ID or tenant name?
Then when I'm authenticated I'm using
var context = new AuthenticationContext(config);
context.acquireToken(context.config.clientId, function(error, token) {
// error is null
var now = new Date();
$.ajax({
url: "https://outlook.office365.com/api/v1.0/me/calendarview",
method: "GET",
data: {
"startdatetime": (new Date()).toISOString(),
"enddatetime": (new Date()).toISOString()
},
headers: {
"Authorization": "Bearer " + token,
"Accept": "application/json; odata.metadata=full",
"Client-Request-Id": clientid, // Some unique machine id?
"User-Agent": navigator.userAgent,
"Date": now.toUTCString()
}
}).then(function(result) {},
function(e) {
console.error(e);
// 401 response, x-ms-diagnostics header = 2000005;reason="The PUID value was not found for [ORGID] identity.";error_category="invalid_user"
});
});
If I manually input an authentication token generated with the same account on https://oauthplay.azurewebsites.net/ it succeeds.