aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared
diff options
context:
space:
mode:
Diffstat (limited to 'shared')
-rw-r--r--shared/models/plugins/register-server-auth.model.ts40
-rw-r--r--shared/models/plugins/register-server-setting.model.ts2
-rw-r--r--shared/models/server/server-config.model.ts16
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 @@
1import { UserRole } from '@shared/models' 1import { UserRole } from '@shared/models'
2import { MOAuthToken } from '@server/typings/models' 2import { MOAuthToken } from '@server/typings/models'
3import * as express from 'express'
3 4
4export type RegisterServerAuthOptions = RegisterServerAuthPassOptions | RegisterServerAuthExternalOptions 5export type RegisterServerAuthOptions = RegisterServerAuthPassOptions | RegisterServerAuthExternalOptions
5 6
6export interface RegisterServerAuthPassOptions { 7export interface RegisterServerAuthenticatedResult {
8 username: string
9 email: string
10 role?: UserRole
11 displayName?: string
12}
13
14export interface RegisterServerExternalAuthenticatedResult extends RegisterServerAuthenticatedResult {
15 req: express.Request
16 res: express.Response
17}
18
19interface 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
31export 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
33export interface RegisterServerAuthExternalOptions { 43export 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
40export interface RegisterServerAuthExternalResult { 50export 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
15export interface RegisteredServerSettings { 15export 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
15export interface RegisteredExternalAuthConfig {
16 npmName: string
17 authName: string
18 authDisplayName: string
19}
20
21export interface RegisteredIdAndPassAuthConfig {
22 npmName: string
23 authName: string
24 weight: number
25}
26
15export interface ServerConfig { 27export 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: {