-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcli.js
executable file
·81 lines (77 loc) · 2.7 KB
/
cli.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env node
require('yargs') // eslint-disable-line
.command('auth [authorizationToken] [secret] [assinanteId]', 'authenticate', (yargs) => {
yargs
.positional('authorizationToken', {
describe: 'authorization token',
default: process.env.AUTHORIZATION_TOKEN
})
.positional('secret', {
describe: 'secret',
default: process.env.SECRET
})
.positional('assinanteId', {
describe: 'assinante id',
default: '*'
})
}, (argv) => {
return authenticate(argv.authorizationToken, argv.secret, argv.assinanteId);
})
.command('auth-payload [authorizationToken] [secret] [assinanteId]', 'generate a payload needed for authentication', (yargs) => {
yargs
.positional('authorizationToken', {
describe: 'authorization token',
default: process.env.AUTHORIZATION_TOKEN
})
.positional('secret', {
describe: 'secret',
default: process.env.SECRET
})
.positional('assinanteId', {
describe: 'assinante id',
default: '*'
})
}, (argv) => {
return generateAuthPayload(argv.authorizationToken, argv.secret, argv.assinanteId);
})
.argv
function generateAuthPayload (authorizationToken, secret, assinanteId) {
const StreamClient = require('./lib/stream-client');
const client = new StreamClient({
authorizationToken,
secret,
assinanteId
});
try {
const object = client._getAuthenticationBody();
console.log('PAYLOAD');
console.log('----------------------------------');
console.log(JSON.stringify(object));
console.log('----------------------------------');
} catch (e) {
console.log(e);
}
}
async function authenticate (authorizationToken, secret, assinanteId) {
const StreamClient = require('./lib/stream-client');
const client = new StreamClient({
authorizationToken,
secret,
assinanteId
});
try {
const { accessToken, refreshToken } = await client._authenticate();
console.log('');
console.log('Access Token');
console.log('----------------------------------');
console.log(accessToken);
console.log('----------------------------------');
console.log('');
console.log('Refresh Token');
console.log('----------------------------------');
console.log(refreshToken);
console.log('----------------------------------');
} catch (e) {
console.log(e);
}
}