-
Notifications
You must be signed in to change notification settings - Fork 0
/
authenticateUrl.js
34 lines (29 loc) · 968 Bytes
/
authenticateUrl.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/* jshint esversion: 6*/
var fs = require('fs');
const {google} = require('googleapis');
var scopes=require('./scope');
function getAuthorizationUrl(cb) {
fs.readFile('authKeys.json',function(err,data) {
if(err) {
return cb(err);
}
var credentials = JSON.parse(data);
var clientSecret = credentials.installed.client_secret;
var clientId = credentials.installed.client_id;
var redirectUrl = credentials.installed.redirect_uris[0];
var oauth2Client = new google.auth.OAuth2(clientId, clientSecret, redirectUrl);
var authUrl = oauth2Client.generateAuthUrl({
access_type: 'offline',
scope: scopes
});
return cb(null, authUrl);
});
}
getAuthorizationUrl(function(err,url) {
if(err) {
console.log('err:',err);
}
else {
console.log('Authorization Url is: \n',url);
}
});