aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/users/login.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-07-11 17:23:24 +0200
committerChocobozzz <chocobozzz@cpy.re>2019-07-24 10:58:16 +0200
commit8d2be0ed7bb87283a1ec98609df6b82d83db706a (patch)
tree31a36b252df32be83ceb77658a53b57f9d15e8ac /shared/extra-utils/users/login.ts
parentdba85a1e9e9f603ba52e1ea42deaf3fdd799b1d8 (diff)
downloadPeerTube-8d2be0ed7bb87283a1ec98609df6b82d83db706a.tar.gz
PeerTube-8d2be0ed7bb87283a1ec98609df6b82d83db706a.tar.zst
PeerTube-8d2be0ed7bb87283a1ec98609df6b82d83db706a.zip
WIP plugins: move plugin CLI in peertube script
Install/uninstall/list plugins remotely
Diffstat (limited to 'shared/extra-utils/users/login.ts')
-rw-r--r--shared/extra-utils/users/login.ts19
1 files changed, 19 insertions, 0 deletions
diff --git a/shared/extra-utils/users/login.ts b/shared/extra-utils/users/login.ts
index ddeb9df2a..f9bfb3cb3 100644
--- a/shared/extra-utils/users/login.ts
+++ b/shared/extra-utils/users/login.ts
@@ -1,6 +1,7 @@
1import * as request from 'supertest' 1import * as request from 'supertest'
2 2
3import { ServerInfo } from '../server/servers' 3import { ServerInfo } from '../server/servers'
4import { getClient } from '../server/clients'
4 5
5type Client = { id: string, secret: string } 6type Client = { id: string, secret: string }
6type User = { username: string, password: string } 7type User = { username: string, password: string }
@@ -38,6 +39,23 @@ async function userLogin (server: Server, user: User, expectedStatus = 200) {
38 return res.body.access_token as string 39 return res.body.access_token as string
39} 40}
40 41
42async function getAccessToken (url: string, username: string, password: string) {
43 const resClient = await getClient(url)
44 const client = {
45 id: resClient.body.client_id,
46 secret: resClient.body.client_secret
47 }
48
49 const user = { username, password }
50
51 try {
52 const res = await login(url, client, user)
53 return res.body.access_token
54 } catch (err) {
55 throw new Error('Cannot authenticate. Please check your username/password.')
56 }
57}
58
41function setAccessTokensToServers (servers: ServerInfo[]) { 59function setAccessTokensToServers (servers: ServerInfo[]) {
42 const tasks: Promise<any>[] = [] 60 const tasks: Promise<any>[] = []
43 61
@@ -55,6 +73,7 @@ export {
55 login, 73 login,
56 serverLogin, 74 serverLogin,
57 userLogin, 75 userLogin,
76 getAccessToken,
58 setAccessTokensToServers, 77 setAccessTokensToServers,
59 Server, 78 Server,
60 Client, 79 Client,