diff options
Diffstat (limited to 'shared/models/plugins/register-server-auth.model.ts')
-rw-r--r-- | shared/models/plugins/register-server-auth.model.ts | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/shared/models/plugins/register-server-auth.model.ts b/shared/models/plugins/register-server-auth.model.ts index 403a49994..08053f017 100644 --- a/shared/models/plugins/register-server-auth.model.ts +++ b/shared/models/plugins/register-server-auth.model.ts | |||
@@ -1,42 +1,52 @@ | |||
1 | import { UserRole } from '@shared/models' | 1 | import { UserRole } from '@shared/models' |
2 | import { MOAuthToken } from '@server/typings/models' | 2 | import { MOAuthToken } from '@server/typings/models' |
3 | import * as express from 'express' | ||
3 | 4 | ||
4 | export type RegisterServerAuthOptions = RegisterServerAuthPassOptions | RegisterServerAuthExternalOptions | 5 | export type RegisterServerAuthOptions = RegisterServerAuthPassOptions | RegisterServerAuthExternalOptions |
5 | 6 | ||
6 | export interface RegisterServerAuthPassOptions { | 7 | export interface RegisterServerAuthenticatedResult { |
8 | username: string | ||
9 | email: string | ||
10 | role?: UserRole | ||
11 | displayName?: string | ||
12 | } | ||
13 | |||
14 | export interface RegisterServerExternalAuthenticatedResult extends RegisterServerAuthenticatedResult { | ||
15 | req: express.Request | ||
16 | res: express.Response | ||
17 | } | ||
18 | |||
19 | interface RegisterServerAuthBase { | ||
7 | // Authentication name (a plugin can register multiple auth strategies) | 20 | // Authentication name (a plugin can register multiple auth strategies) |
8 | authName: string | 21 | authName: string |
9 | 22 | ||
10 | // Called by PeerTube when a user from your plugin logged out | 23 | // Called by PeerTube when a user from your plugin logged out |
11 | onLogout?(): void | 24 | onLogout?(): void |
12 | 25 | ||
13 | // Weight of this authentication so PeerTube tries the auth methods in DESC weight order | ||
14 | getWeight(): number | ||
15 | |||
16 | // Your plugin can hook PeerTube access/refresh token validity | 26 | // Your plugin can hook PeerTube access/refresh token validity |
17 | // So you can control for your plugin the user session lifetime | 27 | // So you can control for your plugin the user session lifetime |
18 | hookTokenValidity?(options: { token: MOAuthToken, type: 'access' | 'refresh' }): Promise<{ valid: boolean }> | 28 | hookTokenValidity?(options: { token: MOAuthToken, type: 'access' | 'refresh' }): Promise<{ valid: boolean }> |
29 | } | ||
30 | |||
31 | export interface RegisterServerAuthPassOptions extends RegisterServerAuthBase { | ||
32 | // Weight of this authentication so PeerTube tries the auth methods in DESC weight order | ||
33 | getWeight(): number | ||
19 | 34 | ||
20 | // Used by PeerTube to login a user | 35 | // Used by PeerTube to login a user |
21 | // Returns null if the login failed, or { username, email } on success | 36 | // Returns null if the login failed, or { username, email } on success |
22 | login(body: { | 37 | login(body: { |
23 | id: string | 38 | id: string |
24 | password: string | 39 | password: string |
25 | }): Promise<{ | 40 | }): Promise<RegisterServerAuthenticatedResult | null> |
26 | username: string | ||
27 | email: string | ||
28 | role?: UserRole | ||
29 | displayName?: string | ||
30 | } | null> | ||
31 | } | 41 | } |
32 | 42 | ||
33 | export interface RegisterServerAuthExternalOptions { | 43 | export interface RegisterServerAuthExternalOptions extends RegisterServerAuthBase { |
34 | // Authentication name (a plugin can register multiple auth strategies) | 44 | // Will be displayed in a block next to the login form |
35 | authName: string | 45 | authDisplayName: string |
36 | 46 | ||
37 | onLogout?: Function | 47 | onAuthRequest: (req: express.Request, res: express.Response) => void |
38 | } | 48 | } |
39 | 49 | ||
40 | export interface RegisterServerAuthExternalResult { | 50 | export interface RegisterServerAuthExternalResult { |
41 | onAuth (options: { username: string, email: string }): void | 51 | userAuthenticated (options: RegisterServerExternalAuthenticatedResult): void |
42 | } | 52 | } |