diff options
author | Chocobozzz <me@florianbigard.com> | 2020-04-24 11:33:01 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-05-04 16:21:39 +0200 |
commit | e307e4fce39853d445d086f92b8c556c363ee15d (patch) | |
tree | 0f3faaf3c73222db0fb55b72260c787aeeeb05eb /shared/extra-utils/users | |
parent | e1c5503114deef954731904695cd40dccfcef555 (diff) | |
download | PeerTube-e307e4fce39853d445d086f92b8c556c363ee15d.tar.gz PeerTube-e307e4fce39853d445d086f92b8c556c363ee15d.tar.zst PeerTube-e307e4fce39853d445d086f92b8c556c363ee15d.zip |
Add ability for auth plugins to hook tokens validity
Diffstat (limited to 'shared/extra-utils/users')
-rw-r--r-- | shared/extra-utils/users/login.ts | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/shared/extra-utils/users/login.ts b/shared/extra-utils/users/login.ts index 2d68337a6..b12b51b8c 100644 --- a/shared/extra-utils/users/login.ts +++ b/shared/extra-utils/users/login.ts | |||
@@ -43,6 +43,24 @@ async function serverLogin (server: Server) { | |||
43 | return res.body.access_token as string | 43 | return res.body.access_token as string |
44 | } | 44 | } |
45 | 45 | ||
46 | function refreshToken (server: ServerInfo, refreshToken: string, expectedStatus = 200) { | ||
47 | const path = '/api/v1/users/token' | ||
48 | |||
49 | const body = { | ||
50 | client_id: server.client.id, | ||
51 | client_secret: server.client.secret, | ||
52 | refresh_token: refreshToken, | ||
53 | response_type: 'code', | ||
54 | grant_type: 'refresh_token' | ||
55 | } | ||
56 | |||
57 | return request(server.url) | ||
58 | .post(path) | ||
59 | .type('form') | ||
60 | .send(body) | ||
61 | .expect(expectedStatus) | ||
62 | } | ||
63 | |||
46 | async function userLogin (server: Server, user: User, expectedStatus = 200) { | 64 | async function userLogin (server: Server, user: User, expectedStatus = 200) { |
47 | const res = await login(server.url, server.client, user, expectedStatus) | 65 | const res = await login(server.url, server.client, user, expectedStatus) |
48 | 66 | ||
@@ -83,6 +101,7 @@ export { | |||
83 | login, | 101 | login, |
84 | logout, | 102 | logout, |
85 | serverLogin, | 103 | serverLogin, |
104 | refreshToken, | ||
86 | userLogin, | 105 | userLogin, |
87 | getAccessToken, | 106 | getAccessToken, |
88 | setAccessTokensToServers, | 107 | setAccessTokensToServers, |