(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