-
-
Save vman/1941ce6c61cebca1bfe3e490ce63185e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function ($) { | |
'use strict'; | |
$(document).ready(function () { | |
getMSGraphAccessToken().then(function (msGraphToken) { | |
$.ajax({ | |
url: "https://graph.microsoft.com/v1.0/groups", | |
headers: { | |
"Accept": "application/json", | |
"Authorization": "Bearer " + msGraphToken | |
}, | |
success: function (data) { | |
console.log(data); | |
}, | |
error: function (jqxr, errorCode, errorThrown) { | |
console.log(jqxr.responseText); | |
} | |
}); | |
}) | |
}); | |
function getMSGraphAccessToken() { | |
var deferred = new jQuery.Deferred(); | |
var requestHeaders = { | |
'X-RequestDigest': $("#__REQUESTDIGEST").val(), | |
"accept": "application/json;odata=nometadata", | |
"content-type": "application/json;odata=nometadata" | |
}; | |
var resourceData = { | |
"resource": "https://graph.microsoft.com", | |
}; | |
$.ajax({ | |
url: _spPageContextInfo.webAbsoluteUrl + "/_api/SP.OAuth.Token/Acquire", | |
headers: requestHeaders, | |
type: "POST", | |
data: JSON.stringify(resourceData), | |
success: function (data) { | |
console.log(data); | |
var msGraphToken = data.access_token; | |
deferred.resolve(msGraphToken); | |
}, | |
error: function (jqxr, errorCode, errorThrown) { | |
console.log(jqxr.responseText); | |
deferred.reject(jqxr.responseText); | |
} | |
}); | |
return deferred.promise(); | |
} | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment