diff options
author | Chocobozzz <me@florianbigard.com> | 2020-04-22 16:07:04 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-05-04 16:21:39 +0200 |
commit | 7fed637506043e4432cbebe041ada0625171cceb (patch) | |
tree | 07f174e17c4b4a0b3d43a0fa6944865c06234338 /shared | |
parent | 8d4197637868d5cde49434e937186b57e40f4b2b (diff) | |
download | PeerTube-7fed637506043e4432cbebe041ada0625171cceb.tar.gz PeerTube-7fed637506043e4432cbebe041ada0625171cceb.tar.zst PeerTube-7fed637506043e4432cbebe041ada0625171cceb.zip |
Begin auth plugin support
Diffstat (limited to 'shared')
-rw-r--r-- | shared/extra-utils/users/login.ts | 11 | ||||
-rw-r--r-- | shared/models/plugins/register-server-auth.model.ts | 33 |
2 files changed, 44 insertions, 0 deletions
diff --git a/shared/extra-utils/users/login.ts b/shared/extra-utils/users/login.ts index 4fe54a74a..2d68337a6 100644 --- a/shared/extra-utils/users/login.ts +++ b/shared/extra-utils/users/login.ts | |||
@@ -27,6 +27,16 @@ function login (url: string, client: Client, user: User, expectedStatus = 200) { | |||
27 | .expect(expectedStatus) | 27 | .expect(expectedStatus) |
28 | } | 28 | } |
29 | 29 | ||
30 | function logout (url: string, token: string, expectedStatus = 200) { | ||
31 | const path = '/api/v1/users/revoke-token' | ||
32 | |||
33 | return request(url) | ||
34 | .post(path) | ||
35 | .set('Authorization', 'Bearer ' + token) | ||
36 | .type('form') | ||
37 | .expect(expectedStatus) | ||
38 | } | ||
39 | |||
30 | async function serverLogin (server: Server) { | 40 | async function serverLogin (server: Server) { |
31 | const res = await login(server.url, server.client, server.user, 200) | 41 | const res = await login(server.url, server.client, server.user, 200) |
32 | 42 | ||
@@ -71,6 +81,7 @@ function setAccessTokensToServers (servers: ServerInfo[]) { | |||
71 | 81 | ||
72 | export { | 82 | export { |
73 | login, | 83 | login, |
84 | logout, | ||
74 | serverLogin, | 85 | serverLogin, |
75 | userLogin, | 86 | userLogin, |
76 | getAccessToken, | 87 | getAccessToken, |
diff --git a/shared/models/plugins/register-server-auth.model.ts b/shared/models/plugins/register-server-auth.model.ts new file mode 100644 index 000000000..34ebbe712 --- /dev/null +++ b/shared/models/plugins/register-server-auth.model.ts | |||
@@ -0,0 +1,33 @@ | |||
1 | import { UserRole } from '@shared/models' | ||
2 | |||
3 | export type RegisterServerAuthOptions = RegisterServerAuthPassOptions | RegisterServerAuthExternalOptions | ||
4 | |||
5 | export interface RegisterServerAuthPassOptions { | ||
6 | type: 'id-and-pass' | ||
7 | |||
8 | onLogout?: Function | ||
9 | |||
10 | getWeight(): number | ||
11 | |||
12 | // Used by PeerTube to login a user | ||
13 | // Returns null if the login failed, or { username, email } on success | ||
14 | login(body: { | ||
15 | id: string | ||
16 | password: string | ||
17 | }): Promise<{ | ||
18 | username: string | ||
19 | email: string | ||
20 | role?: UserRole | ||
21 | displayName?: string | ||
22 | } | null> | ||
23 | } | ||
24 | |||
25 | export interface RegisterServerAuthExternalOptions { | ||
26 | type: 'external' | ||
27 | |||
28 | onLogout?: Function | ||
29 | } | ||
30 | |||
31 | export interface RegisterServerAuthExternalResult { | ||
32 | onAuth (options: { username: string, email: string }): void | ||
33 | } | ||