diff options
Diffstat (limited to 'server/tools/peertube-get-access-token.ts')
-rw-r--r-- | server/tools/peertube-get-access-token.ts | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/server/tools/peertube-get-access-token.ts b/server/tools/peertube-get-access-token.ts new file mode 100644 index 000000000..eb2571a03 --- /dev/null +++ b/server/tools/peertube-get-access-token.ts | |||
@@ -0,0 +1,51 @@ | |||
1 | import * as program from 'commander' | ||
2 | |||
3 | import { | ||
4 | getClient, | ||
5 | serverLogin, | ||
6 | Server, | ||
7 | Client, | ||
8 | User | ||
9 | } from '../tests/utils/index' | ||
10 | |||
11 | program | ||
12 | .option('-u, --url <url>', 'Server url') | ||
13 | .option('-n, --username <username>', 'Username') | ||
14 | .option('-p, --password <token>', 'Password') | ||
15 | .parse(process.argv) | ||
16 | |||
17 | if ( | ||
18 | !program['url'] || | ||
19 | !program['username'] || | ||
20 | !program['password'] | ||
21 | ) { | ||
22 | if (!program['url']) console.error('--url field is required.') | ||
23 | if (!program['username']) console.error('--username field is required.') | ||
24 | if (!program['password']) console.error('--password field is required.') | ||
25 | process.exit(-1) | ||
26 | } | ||
27 | |||
28 | getClient(program.url) | ||
29 | .then(res => { | ||
30 | const server = { | ||
31 | url: program['url'], | ||
32 | user: { | ||
33 | username: program['username'], | ||
34 | password: program['password'] | ||
35 | } as User, | ||
36 | client: { | ||
37 | id: res.body.client_id as string, | ||
38 | secret: res.body.client_secret as string | ||
39 | } as Client | ||
40 | } as Server | ||
41 | |||
42 | return serverLogin(server) | ||
43 | }) | ||
44 | .then(accessToken => { | ||
45 | console.log(accessToken) | ||
46 | process.exit(0) | ||
47 | }) | ||
48 | .catch(err => { | ||
49 | console.error(err) | ||
50 | process.exit(-1) | ||
51 | }) | ||