How fetch/get access token from a Microsoft Graph API?
Fetch access token from a Microsoft Graph API/REST API:
function fetchTokenfromGraph() {
$.ajax({
"async": true,
"crossDomain": true,
"url": "https://cors-anywhere.herokuapp.com/https://login.microsoftonline.com/********-****-****-*****-*******/oauth2/v2.0/token", // Pass your tenant id instead of star symbol
"method": "POST",
"headers": {
"content-type": "application/x-www-form-urlencoded"
},
"data": {
"grant_type": "client_credentials", //keep it as it is
"client_id ": "********-****-****-****-********", //Provide your app client id
"client_secret": "ABCDhsj.K8Sa6a:r/raj]Vs02ssd3", //Provide your client secret genereated from sharepoint Azure AD
"scope ": "https://graph.microsoft.com/.default"//keep it as it is
},
success: function (res) {
console.log(res);
},
error: function (e) {
console.log(e);
}
});
}
Comments
Post a Comment