]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/real-world/tools/get-access-token.ts
Convert real world tools to typescript
[github/Chocobozzz/PeerTube.git] / server / tests / real-world / tools / get-access-token.ts
1 import * as program from 'commander'
2 import * as Promise from 'bluebird'
3
4 import {
5 getClient,
6 loginAndGetAccessToken
7 } from '../../utils'
8
9 program
10 .option('-u, --url <url>', 'Server url')
11 .option('-n, --username <username>', 'Username')
12 .option('-p, --password <token>', 'Password')
13 .parse(process.argv)
14
15 if (
16 !program['url'] ||
17 !program['username'] ||
18 !program['password']
19 ) {
20 throw new Error('All arguments are required.')
21 }
22
23 const server = {
24 url: program['url'],
25 user: {
26 username: program['username'],
27 password: program['password']
28 },
29 client: {
30 id: null,
31 secret: null
32 }
33 }
34
35 getClient(program.url)
36 .then(res => {
37 server.client.id = res.body.client_id
38 server.client.secret = res.body.client_secret
39
40 return loginAndGetAccessToken(server)
41 })
42 .then(accessToken => {
43 console.log(accessToken)
44 process.exit(0)
45 })
46 .catch(err => {
47 console.error(err)
48 process.exit(-1)
49 })