-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathgenerate-refresh-token.js
More file actions
35 lines (29 loc) · 1010 Bytes
/
Copy pathgenerate-refresh-token.js
File metadata and controls
35 lines (29 loc) · 1010 Bytes
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
35
'use strict';
var google = require('googleapis');
var Bluebird = require('bluebird');
var OAuth2 = google.auth.OAuth2;
var argv = require('minimist')(process.argv.slice(2));
var config = argv.config || './local/application-creds';
var DFP_CREDS = require(config);
// Constants and arguments.
var AUTH_CODE = argv.authCode;
function getRefreshToken () {
var oauth2Client;
var msg = 'Getting new refresh token with auth code %s...';
console.log(msg, AUTH_CODE); // eslint-disable-line no-console
oauth2Client = new OAuth2(
DFP_CREDS.installed.client_id,
DFP_CREDS.installed.client_secret,
DFP_CREDS.installed.redirect_uris[0]
);
oauth2Client.getToken(AUTH_CODE, function showToken (error, token) {
var tokenMsg = 'Got refresh token: %s';
if (error) {
console.error('Error: ', error); // eslint-disable-line no-console
} else {
console.log(tokenMsg, token.refresh_token); // eslint-disable-line no-console
}
});
}
// Kick things off.
getRefreshToken();