Skip to content
This repository has been archived by the owner on Aug 7, 2021. It is now read-only.

Commit

Permalink
add windows graph sample
Browse files Browse the repository at this point in the history
  • Loading branch information
Wesley Yao authored and lovemaths committed Oct 26, 2017
1 parent 7588f96 commit c8de325
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions sample/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
, "version": "0.0.1"
, "private": true
, "dependencies": {
"@microsoft/microsoft-graph-client": "^1.0.0",
"adal-node": ">= 0.1.3",
"express": "3.x",
"connect-logger": "0.x",
Expand Down
34 changes: 34 additions & 0 deletions sample/windows-graph-sample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const AuthenticationContext = require('adal-node').AuthenticationContext;
const MicrosoftGraph = require("@microsoft/microsoft-graph-client");

const authorityHostUrl = 'https://login.windows.net';
const tenantName = ''; //azure active directory tenant name. ie: name.onmicrosoft.com
const authorityUrl = authorityHostUrl + '/' + tenantName;
const applicationId = ''; //application id for registered app
const clientSecret = ''; //azure active directory registered app secret
const resource = "https://graph.microsoft.com"; //URI of resource where token is valid

const context = new AuthenticationContext(authorityUrl);

context.acquireTokenWithClientCredentials(
resource,
applicationId,
clientSecret,
function(err, tokenResponse) {
if (err) {
console.log('well that didn\'t work: ' + err.stack);
} else {
let client = MicrosoftGraph.Client.init({
defaultVersion: 'v1.0',
authProvider: (done) => {
done(null, tokenResponse.accessToken);
},
});

client
.api('/users')
.get((err, result) => {
console.log(result, err);
});
}
});

0 comments on commit c8de325

Please sign in to comment.