Skip to content

Instantly share code, notes, and snippets.

@andrei-markeev
Created March 14, 2018 09:57
Show Gist options
  • Save andrei-markeev/12f8e17a44957a04a2dc818ab22a5ea3 to your computer and use it in GitHub Desktop.
Save andrei-markeev/12f8e17a44957a04a2dc818ab22a5ea3 to your computer and use it in GitHub Desktop.
Azure Function get MS Graph access token
async function getMSGraphAccessToken() {
var body = {
grant_type: 'client_credentials',
client_id: process.env.AZURE_APP_ID,
client_secret: process.env.AZURE_APP_SECRET,
resource: 'https://graph.microsoft.com'
};
var responseText = await request('https://login.windows.net/' + process.env.AZURE_TENANT_ID + '/oauth2/token', { method: 'POST', body, format: 'urlencoded' });
var access_token = JSON.parse(responseText).access_token;
return access_token;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment