]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tools/get-access-token.ts
Move subscription helper in the account line
[github/Chocobozzz/PeerTube.git] / server / tools / 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 throw new Error('All arguments are required.')
23 }
24
25 getClient(program.url)
26 .then(res => {
27 const server = {
28 url: program['url'],
29 user: {
30 username: program['username'],
31 password: program['password']
32 } as User,
33 client: {
34 id: res.body.client_id as string,
35 secret: res.body.client_secret as string
36 } as Client
37 } as Server
38
39 return serverLogin(server)
40 })
41 .then(accessToken => {
42 console.log(accessToken)
43 process.exit(0)
44 })
45 .catch(err => {
46 console.error(err)
47 process.exit(-1)
48 })