diff options
Diffstat (limited to 'shared/models')
-rw-r--r-- | shared/models/plugins/register-server-auth.model.ts | 40 | ||||
-rw-r--r-- | shared/models/plugins/register-server-setting.model.ts | 2 | ||||
-rw-r--r-- | shared/models/server/server-config.model.ts | 16 |
3 files changed, 42 insertions, 16 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 | } |
diff --git a/shared/models/plugins/register-server-setting.model.ts b/shared/models/plugins/register-server-setting.model.ts index ec175e9ef..920c3480f 100644 --- a/shared/models/plugins/register-server-setting.model.ts +++ b/shared/models/plugins/register-server-setting.model.ts | |||
@@ -9,7 +9,7 @@ export interface RegisterServerSettingOptions { | |||
9 | private: boolean | 9 | private: boolean |
10 | 10 | ||
11 | // Default setting value | 11 | // Default setting value |
12 | default?: string | 12 | default?: string | boolean |
13 | } | 13 | } |
14 | 14 | ||
15 | export interface RegisteredServerSettings { | 15 | export interface RegisteredServerSettings { |
diff --git a/shared/models/server/server-config.model.ts b/shared/models/server/server-config.model.ts index c3976a346..0ff079216 100644 --- a/shared/models/server/server-config.model.ts +++ b/shared/models/server/server-config.model.ts | |||
@@ -12,6 +12,18 @@ export interface ServerConfigTheme extends ServerConfigPlugin { | |||
12 | css: string[] | 12 | css: string[] |
13 | } | 13 | } |
14 | 14 | ||
15 | export interface RegisteredExternalAuthConfig { | ||
16 | npmName: string | ||
17 | authName: string | ||
18 | authDisplayName: string | ||
19 | } | ||
20 | |||
21 | export interface RegisteredIdAndPassAuthConfig { | ||
22 | npmName: string | ||
23 | authName: string | ||
24 | weight: number | ||
25 | } | ||
26 | |||
15 | export interface ServerConfig { | 27 | export interface ServerConfig { |
16 | serverVersion: string | 28 | serverVersion: string |
17 | serverCommit?: string | 29 | serverCommit?: string |
@@ -37,6 +49,10 @@ export interface ServerConfig { | |||
37 | 49 | ||
38 | plugin: { | 50 | plugin: { |
39 | registered: ServerConfigPlugin[] | 51 | registered: ServerConfigPlugin[] |
52 | |||
53 | registeredExternalAuths: RegisteredExternalAuthConfig[] | ||
54 | |||
55 | registeredIdAndPassAuths: RegisteredIdAndPassAuthConfig[] | ||
40 | } | 56 | } |
41 | 57 | ||
42 | theme: { | 58 | theme: { |