Created
March 20, 2019 00:23
-
-
Save phillipharding/3f5661f54456efae7168fd700aeb0a54 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
(async function() { | |
function getAccessToken(resource) { | |
return new Promise( async (resolve, reject) => { | |
var body = { | |
"resource": resource || "https://graph.microsoft.com" | |
}; | |
const url = `${_spPageContextInfo.webAbsoluteUrl}/_api/SP.OAuth.Token/Acquire`; | |
const response = await fetch(url, { | |
"method": "POST", | |
"headers": { | |
"X-RequestDigest": _spPageContextInfo.formDigestValue, | |
"Accept": "application/json;odata=nometadata", | |
"Content-Type": "application/json;odata=nometadata" | |
}, | |
"body": JSON.stringify(body) | |
}); | |
const data = await response.json(); | |
console.info(data); | |
var accessToken = data.access_token; | |
resolve(accessToken); | |
}); | |
} | |
function getGroups(accessToken) { | |
return new Promise( async (resolve, reject) => { | |
const url = `https://graph.microsoft.com/v1.0/groups`; | |
const response = await fetch(url, { | |
"method": "GET", | |
"headers": { | |
"Accept": "application/json", | |
"Authorization": `Bearer ${accessToken}`, | |
}, | |
}); | |
const data = await response.json(); | |
console.info(data); | |
resolve(data); | |
}); | |
} | |
console.clear(); | |
const accessToken = await getAccessToken("https://graph.microsoft.com"); | |
console.info("accessToken", accessToken); | |
const groups = await getGroups(accessToken); | |
console.info("groups", groups.value); | |
})(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment