]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tools/peertube-get-access-token.ts
one cli to unite them all
[github/Chocobozzz/PeerTube.git] / server / tools / peertube-get-access-token.ts
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 })