]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tools/get-access-token.ts
Begin import script with youtube-dl
[github/Chocobozzz/PeerTube.git] / server / tools / get-access-token.ts
1 import * as program from 'commander'
2
3 import {
4 getClient,
5 serverLogin
6 } from '../tests/utils/index'
7
8 program
9 .option('-u, --url <url>', 'Server url')
10 .option('-n, --username <username>', 'Username')
11 .option('-p, --password <token>', 'Password')
12 .parse(process.argv)
13
14 if (
15 !program['url'] ||
16 !program['username'] ||
17 !program['password']
18 ) {
19 throw new Error('All arguments are required.')
20 }
21
22 const server = {
23 url: program['url'],
24 user: {
25 username: program['username'],
26 password: program['password']
27 },
28 client: {
29 id: null,
30 secret: null
31 }
32 }
33
34 getClient(program.url)
35 .then(res => {
36 server.client.id = res.body.client_id
37 server.client.secret = res.body.client_secret
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 })