@@ -37,7 +37,7 @@ fs.readFile(options.credentialFile, (err, content) => {
37
37
rl . close ( ) ;
38
38
console . log ( `You chose ${ code } ` ) ;
39
39
// Authorize a client with credentials, then call the Google Slides API.
40
- authorize ( JSON . parse ( content ) , currentTokens , code , listTaskLists ) ;
40
+ authorize ( options . tokenFile , JSON . parse ( content ) , currentTokens , code , listTaskLists ) ;
41
41
} ) ;
42
42
43
43
@@ -49,7 +49,7 @@ fs.readFile(options.credentialFile, (err, content) => {
49
49
* @param {Object } credentials The authorization client credentials.
50
50
* @param {function } callback The callback to call with the authorized client.
51
51
*/
52
- function authorize ( credentials , currentTokens , account , callback ) {
52
+ function authorize ( tokenPath , credentials , currentTokens , account , callback ) {
53
53
const { client_secret, client_id, redirect_uris} = credentials . installed ;
54
54
const oAuth2Client = new google . auth . OAuth2 (
55
55
client_id , client_secret , redirect_uris [ 0 ] ) ;
@@ -58,7 +58,7 @@ function authorize(credentials, currentTokens, account, callback) {
58
58
59
59
if ( ! existingToken )
60
60
{
61
- getNewToken ( oAuth2Client , currentTokens , account , callback ) ;
61
+ getNewToken ( tokenPath , oAuth2Client , currentTokens , account , callback ) ;
62
62
}
63
63
else
64
64
{
@@ -73,7 +73,7 @@ function authorize(credentials, currentTokens, account, callback) {
73
73
* @param {google.auth.OAuth2 } oAuth2Client The OAuth2 client to get token for.
74
74
* @param {getEventsCallback } callback The callback for the authorized client.
75
75
*/
76
- function getNewToken ( oAuth2Client , currentTokens , account , callback ) {
76
+ function getNewToken ( tokenPath , oAuth2Client , currentTokens , account , callback ) {
77
77
const authUrl = oAuth2Client . generateAuthUrl ( {
78
78
access_type : 'offline' ,
79
79
scope : SCOPES ,
@@ -89,7 +89,10 @@ function getNewToken(oAuth2Client, currentTokens, account, callback) {
89
89
rl . question ( 'Enter the code from that page here: ' , ( code ) => {
90
90
rl . close ( ) ;
91
91
oAuth2Client . getToken ( code , ( err , token ) => {
92
- if ( err ) return callback ( err ) ;
92
+ if ( err ) {
93
+ console . log ( "Error: " + err ) ;
94
+ return callback ( err ) ;
95
+ }
93
96
oAuth2Client . setCredentials ( token ) ;
94
97
95
98
if ( existingToken ) {
@@ -103,9 +106,9 @@ function getNewToken(oAuth2Client, currentTokens, account, callback) {
103
106
}
104
107
105
108
// Store the token to disk for later program executions
106
- fs . writeFile ( TOKEN_PATH , JSON . stringify ( currentTokens ) , ( err ) => {
109
+ fs . writeFile ( tokenPath , JSON . stringify ( currentTokens ) , ( err ) => {
107
110
if ( err ) console . error ( err ) ;
108
- console . log ( 'Token stored to' , TOKEN_PATH ) ;
111
+ console . log ( 'Token stored to' , tokenPath ) ;
109
112
} ) ;
110
113
callback ( oAuth2Client ) ;
111
114
} ) ;
0 commit comments