-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathduckietv-builder-oauth-init.js
executable file
·39 lines (32 loc) · 1.15 KB
/
duckietv-builder-oauth-init.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
35
36
37
38
39
#!/usr/bin/env node
require('shelljs/global');
var program = require('commander'),
shared = require('./shared'),
opn = require('opn'),
oauth = require('./oauth');
config.verbose = false;
config.fatal = true;
/**
* Oauth initialisation for Chrome Webstore API
* - Launches a browser where oauth grant is given and a one-time auth token can be copied from
* - performs initial token request to grab access token, refresh token and max age
* - stores these in ~/.duckietv-builder.json
*/
program
.description('Initialize oAuth token for chrome webstore api in ~/.duckietv-builder.json')
.parse(process.argv);
var credentials = shared.getCredentials();
echo("Opening browser. Close the browser when you're done and paste the code here");
opn(oAuth.getApprovalPromptURL());
echo("paste the code here:\n");
process.stdin.setEncoding('utf8');
process.stdin.once('data', function(code) {
var response = require('./oauth').generateInitialToken(code);
if (response.error) {
echo("Error:\n", response.error);
process.exit();
} else {
echo("Credentials updated successfully.");
process.exit();
}
}).resume();