]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tools/peertube-get-access-token.ts
Merge remote-tracking branch 'weblate/develop' into develop
[github/Chocobozzz/PeerTube.git] / server / tools / peertube-get-access-token.ts
1 import { registerTSPaths } from '../helpers/register-ts-paths'
2 registerTSPaths()
3
4 import * as program from 'commander'
5 import { getClient, Server, serverLogin } from '../../shared/extra-utils'
6
7 program
8 .option('-u, --url <url>', 'Server url')
9 .option('-n, --username <username>', 'Username')
10 .option('-p, --password <token>', 'Password')
11 .parse(process.argv)
12
13 const options = program.opts()
14
15 if (
16 !options.url ||
17 !options.username ||
18 !options.password
19 ) {
20 if (!options.url) console.error('--url field is required.')
21 if (!options.username) console.error('--username field is required.')
22 if (!options.password) console.error('--password field is required.')
23
24 process.exit(-1)
25 }
26
27 getClient(options.url)
28 .then(res => {
29 const server = {
30 url: options.url,
31 user: {
32 username: options.username,
33 password: options.password
34 },
35 client: {
36 id: res.body.client_id,
37 secret: res.body.client_secret
38 }
39 } as Server
40
41 return serverLogin(server)
42 })
43 .then(accessToken => {
44 console.log(accessToken)
45 process.exit(0)
46 })
47 .catch(err => {
48 console.error(err)
49 process.exit(-1)
50 })