]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tools/peertube-get-access-token.ts
Translated using Weblate (Russian)
[github/Chocobozzz/PeerTube.git] / server / tools / peertube-get-access-token.ts
CommitLineData
2aaa1a3f
C
1import { registerTSPaths } from '../helpers/register-ts-paths'
2registerTSPaths()
3
8df87ce7 4import * as program from 'commander'
1a12f66d 5import { getClient, Server, serverLogin } from '../../shared/extra-utils'
8df87ce7
C
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) {
8704acf4
RK
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.')
1a12f66d 21
8704acf4 22 process.exit(-1)
8df87ce7
C
23}
24
8df87ce7
C
25getClient(program.url)
26 .then(res => {
c1e791ba
RK
27 const server = {
28 url: program['url'],
29 user: {
30 username: program['username'],
31 password: program['password']
1a12f66d 32 },
c1e791ba 33 client: {
1a12f66d
C
34 id: res.body.client_id,
35 secret: res.body.client_secret
36 }
c1e791ba 37 } as Server
8df87ce7 38
eec63bbc 39 return serverLogin(server)
8df87ce7
C
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 })