aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tools/peertube-get-access-token.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-09-20 16:24:49 +0200
committerGitHub <noreply@github.com>2018-09-20 16:24:49 +0200
commitdc27668fceb1d0270c391c93c3bbc95d12e83218 (patch)
treece6621597505f9518cfdf0981977d097c63f9fad /server/tools/peertube-get-access-token.ts
parent6247b2057b792cea155a1abd9788c363ae7d2cc2 (diff)
parent0491173a61aed66205c017e0d7e0503ea316c144 (diff)
downloadPeerTube-dc27668fceb1d0270c391c93c3bbc95d12e83218.tar.gz
PeerTube-dc27668fceb1d0270c391c93c3bbc95d12e83218.tar.zst
PeerTube-dc27668fceb1d0270c391c93c3bbc95d12e83218.zip
Merge pull request #941 from rigelk/cli-wrapper
adding cli wrapper
Diffstat (limited to 'server/tools/peertube-get-access-token.ts')
-rw-r--r--server/tools/peertube-get-access-token.ts51
1 files changed, 51 insertions, 0 deletions
diff --git a/server/tools/peertube-get-access-token.ts b/server/tools/peertube-get-access-token.ts
new file mode 100644
index 000000000..eb2571a03
--- /dev/null
+++ b/server/tools/peertube-get-access-token.ts
@@ -0,0 +1,51 @@
1import * as program from 'commander'
2
3import {
4 getClient,
5 serverLogin,
6 Server,
7 Client,
8 User
9} from '../tests/utils/index'
10
11program
12 .option('-u, --url <url>', 'Server url')
13 .option('-n, --username <username>', 'Username')
14 .option('-p, --password <token>', 'Password')
15 .parse(process.argv)
16
17if (
18 !program['url'] ||
19 !program['username'] ||
20 !program['password']
21) {
22 if (!program['url']) console.error('--url field is required.')
23 if (!program['username']) console.error('--username field is required.')
24 if (!program['password']) console.error('--password field is required.')
25 process.exit(-1)
26}
27
28getClient(program.url)
29 .then(res => {
30 const server = {
31 url: program['url'],
32 user: {
33 username: program['username'],
34 password: program['password']
35 } as User,
36 client: {
37 id: res.body.client_id as string,
38 secret: res.body.client_secret as string
39 } as Client
40 } as Server
41
42 return serverLogin(server)
43 })
44 .then(accessToken => {
45 console.log(accessToken)
46 process.exit(0)
47 })
48 .catch(err => {
49 console.error(err)
50 process.exit(-1)
51 })