Skip to content

Instantly share code, notes, and snippets.

@nbellocam
Created February 6, 2018 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nbellocam/b2cb28d8ed79f51a4bcd891bb537a6f2 to your computer and use it in GitHub Desktop.
Save nbellocam/b2cb28d8ed79f51a4bcd891bb537a6f2 to your computer and use it in GitHub Desktop.
Calling Microsoft Graph API from an Azure Function using JavaScript - getToken Function
var adal = require('adal-node');
const TENANT = "{tenant-name-here}.onmicrosoft.com";
const CLIENT_ID = "{Application-id-here}";
const CLIENT_SECRET = "{Application-key-here}";
function getToken() {
return new Promise((resolve, reject) => {
const authContext = new adal.AuthenticationContext(`https://login.microsoftonline.com/${TENANT}`);
authContext.acquireTokenWithClientCredentials(GRAPH_URL, CLIENT_ID, CLIENT_SECRET, (err, tokenRes) => {
if (err) { reject(err); }
resolve(tokenRes.accessToken);
});
});
}
@hardy925
Copy link

hardy925 commented Jan 2, 2019

var adal = require('adal-node'); => const adal = require('adal-node');

Seems like you are mixing ECMAScript's together.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment