I don't hate Oauth, but I hate myself for not being able to wrap my head around the concept. Having said that, here's my question: I'm trying to call the Office Graph REST api from vanilla javascript. So I'm doing a regular XMLHttpRequest to graph.microsoft.com, from a page which runs on my SharePoint Online site (therefore the code should run from my security context, as I am logged in). The call returns a 403 Authentication Required. I assume I have to register an app in Azure AD and I have done that, so I have a Client ID and a secret. However, I cannot find what to do next programmatically (I think I understand the concept, I have to get a token that I have to provide when calling the Graph api). It seems there's tons of sample code for just about anything, with the exception of javascript. Does anyone have pointers?
Update: I know the involvement of the token, and that's the part I can't wrap my head around (see original question/comment); I have a Client ID, I have a secret, and I have this (VERY common) code:
function graphRead(whatToRead) {
switch(whatToRead) {
case "userinfo" :
officeUser = JSON.Parse(loadXMLDoc("GET","https://graph.microsoft.com/v1.0/me"));
break;
default:
};
};
function loadXMLDoc(mMethod,uURL) {
var xmlhttp;
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == XMLHttpRequest.DONE ) {
if(xmlhttp.status == 200){
return(xmlhttp.responseText);
}
else if(xmlhttp.status == 400) {
alert('There was an error 400')
}
else {
alert('something else other than 200 was returned')
}
}
};
xmlhttp.open(mMethod, uURL, true);
xmlhttp.send();
};
Question is: what do I need to do to establish the token and send it to the API?