From 8d2be0ed7bb87283a1ec98609df6b82d83db706a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 11 Jul 2019 17:23:24 +0200 Subject: WIP plugins: move plugin CLI in peertube script Install/uninstall/list plugins remotely --- shared/extra-utils/users/login.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'shared/extra-utils/users/login.ts') 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 @@ import * as request from 'supertest' import { ServerInfo } from '../server/servers' +import { getClient } from '../server/clients' type Client = { id: string, secret: string } type User = { username: string, password: string } @@ -38,6 +39,23 @@ async function userLogin (server: Server, user: User, expectedStatus = 200) { return res.body.access_token as string } +async function getAccessToken (url: string, username: string, password: string) { + const resClient = await getClient(url) + const client = { + id: resClient.body.client_id, + secret: resClient.body.client_secret + } + + const user = { username, password } + + try { + const res = await login(url, client, user) + return res.body.access_token + } catch (err) { + throw new Error('Cannot authenticate. Please check your username/password.') + } +} + function setAccessTokensToServers (servers: ServerInfo[]) { const tasks: Promise[] = [] @@ -55,6 +73,7 @@ export { login, serverLogin, userLogin, + getAccessToken, setAccessTokensToServers, Server, Client, -- cgit v1.2.3