]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tools/peertube-get-access-token.ts
Fix comment notifications
[github/Chocobozzz/PeerTube.git] / server / tools / peertube-get-access-token.ts
CommitLineData
8df87ce7 1import * as program from 'commander'
1a12f66d 2import { getClient, Server, serverLogin } from '../../shared/extra-utils'
8df87ce7
C
3
4program
5 .option('-u, --url <url>', 'Server url')
6 .option('-n, --username <username>', 'Username')
7 .option('-p, --password <token>', 'Password')
8 .parse(process.argv)
9
10if (
11 !program['url'] ||
12 !program['username'] ||
13 !program['password']
14) {
8704acf4
RK
15 if (!program['url']) console.error('--url field is required.')
16 if (!program['username']) console.error('--username field is required.')
17 if (!program['password']) console.error('--password field is required.')
1a12f66d 18
8704acf4 19 process.exit(-1)
8df87ce7
C
20}
21
8df87ce7
C
22getClient(program.url)
23 .then(res => {
c1e791ba
RK
24 const server = {
25 url: program['url'],
26 user: {
27 username: program['username'],
28 password: program['password']
1a12f66d 29 },
c1e791ba 30 client: {
1a12f66d
C
31 id: res.body.client_id,
32 secret: res.body.client_secret
33 }
c1e791ba 34 } as Server
8df87ce7 35
eec63bbc 36 return serverLogin(server)
8df87ce7
C
37 })
38 .then(accessToken => {
39 console.log(accessToken)
40 process.exit(0)
41 })
42 .catch(err => {
43 console.error(err)
44 process.exit(-1)
45 })