]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/tools/peertube-get-access-token.ts
Update credits
[github/Chocobozzz/PeerTube.git] / server / tools / peertube-get-access-token.ts
... / ...
CommitLineData
1import { registerTSPaths } from '../helpers/register-ts-paths'
2registerTSPaths()
3
4import * as program from 'commander'
5import { getClient, Server, serverLogin } from '../../shared/extra-utils'
6
7program
8 .option('-u, --url <url>', 'Server url')
9 .option('-n, --username <username>', 'Username')
10 .option('-p, --password <token>', 'Password')
11 .parse(process.argv)
12
13if (
14 !program['url'] ||
15 !program['username'] ||
16 !program['password']
17) {
18 if (!program['url']) console.error('--url field is required.')
19 if (!program['username']) console.error('--username field is required.')
20 if (!program['password']) console.error('--password field is required.')
21
22 process.exit(-1)
23}
24
25getClient(program.url)
26 .then(res => {
27 const server = {
28 url: program['url'],
29 user: {
30 username: program['username'],
31 password: program['password']
32 },
33 client: {
34 id: res.body.client_id,
35 secret: res.body.client_secret
36 }
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 })