]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tools/peertube-get-access-token.ts
Upgrade server dependencies
[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
ba5a8d89
C
13const options = program.opts()
14
8df87ce7 15if (
ba5a8d89
C
16 !options.url ||
17 !options.username ||
18 !options.password
8df87ce7 19) {
ba5a8d89
C
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.')
1a12f66d 23
8704acf4 24 process.exit(-1)
8df87ce7
C
25}
26
ba5a8d89 27getClient(options.url)
8df87ce7 28 .then(res => {
c1e791ba 29 const server = {
ba5a8d89 30 url: options.url,
c1e791ba 31 user: {
ba5a8d89
C
32 username: options.username,
33 password: options.password
1a12f66d 34 },
c1e791ba 35 client: {
1a12f66d
C
36 id: res.body.client_id,
37 secret: res.body.client_secret
38 }
c1e791ba 39 } as Server
8df87ce7 40
eec63bbc 41 return serverLogin(server)
8df87ce7
C
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 })