aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-04-22 16:07:04 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-05-04 16:21:39 +0200
commit7fed637506043e4432cbebe041ada0625171cceb (patch)
tree07f174e17c4b4a0b3d43a0fa6944865c06234338 /shared
parent8d4197637868d5cde49434e937186b57e40f4b2b (diff)
downloadPeerTube-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.ts11
-rw-r--r--shared/models/plugins/register-server-auth.model.ts33
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
30function 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
30async function serverLogin (server: Server) { 40async 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
72export { 82export {
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 @@
1import { UserRole } from '@shared/models'
2
3export type RegisterServerAuthOptions = RegisterServerAuthPassOptions | RegisterServerAuthExternalOptions
4
5export 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
25export interface RegisterServerAuthExternalOptions {
26 type: 'external'
27
28 onLogout?: Function
29}
30
31export interface RegisterServerAuthExternalResult {
32 onAuth (options: { username: string, email: string }): void
33}