aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/users/login.ts
diff options
context:
space:
mode:
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,