Skip to content
This repository was archived by the owner on Mar 13, 2020. It is now read-only.

Commit c8d7485

Browse files
authored
Merge pull request #17 from burashka/master
Move code to ES2017
2 parents f62fa00 + 6e059a3 commit c8d7485

4 files changed

Lines changed: 222 additions & 232 deletions

File tree

‎authHelper.js‎

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,50 @@
11
// Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See LICENSE.txt in the project root for license information.
2-
var credentials = {
2+
const credentials = {
33
client: {
4-
id: 'YOUR APP ID HERE',
5-
secret: 'YOUR APP PASSWORD HERE',
4+
id: 'YOUR APP ID HERE',
5+
secret: 'YOUR APP PASSWORD HERE',
66
},
77
auth: {
88
tokenHost: 'https://login.microsoftonline.com',
99
authorizePath: 'common/oauth2/v2.0/authorize',
1010
tokenPath: 'common/oauth2/v2.0/token'
1111
}
1212
};
13-
var oauth2 = require('simple-oauth2').create(credentials);
13+
const oauth2 = require('simple-oauth2').create(credentials);
1414

15-
var redirectUri = 'http://localhost:8000/authorize';
15+
const redirectUri = 'http://localhost:8000/authorize';
1616

1717
// The scopes the app requires
18-
var scopes = [ 'openid',
18+
const scopes = [ 'openid',
1919
'offline_access',
2020
'User.Read',
2121
'Mail.Read',
2222
'Calendars.Read',
2323
'Contacts.Read' ];
2424

2525
function getAuthUrl() {
26-
var returnVal = oauth2.authorizationCode.authorizeURL({
26+
const returnVal = oauth2.authorizationCode.authorizeURL({
2727
redirect_uri: redirectUri,
2828
scope: scopes.join(' ')
2929
});
3030
console.log('Generated auth url: ' + returnVal);
3131
return returnVal;
3232
}
3333

34-
function getTokenFromCode(auth_code, callback, response) {
35-
var token;
36-
oauth2.authorizationCode.getToken({
37-
code: auth_code,
38-
redirect_uri: redirectUri,
39-
scope: scopes.join(' ')
40-
}, function (error, result) {
41-
if (error) {
42-
console.log('Access token error: ', error.message);
43-
callback(response, error, null);
44-
} else {
45-
token = oauth2.accessToken.create(result);
46-
console.log('Token created: ', token.token);
47-
callback(response, null, token);
48-
}
49-
});
34+
async function getTokenFromCode(auth_code) {
35+
let result = await oauth2.authorizationCode.getToken({
36+
code: auth_code,
37+
redirect_uri: redirectUri,
38+
scope: scopes.join(' ')
39+
});
40+
41+
const token = oauth2.accessToken.create(result);
42+
console.log('Token created: ', token.token);
43+
return token;
5044
}
5145

52-
function refreshAccessToken(refreshToken, callback) {
53-
var tokenObj = oauth2.accessToken.create({refresh_token: refreshToken});
54-
tokenObj.refresh(callback);
46+
function refreshAccessToken(refreshToken) {
47+
return oauth2.accessToken.create({refresh_token: refreshToken}).refresh();
5548
}
5649

5750
exports.getAuthUrl = getAuthUrl;

0 commit comments

Comments
 (0)