diff options
Diffstat (limited to 'server/lib/plugins')
-rw-r--r-- | server/lib/plugins/plugin-manager.ts | 13 | ||||
-rw-r--r-- | server/lib/plugins/register-helpers-store.ts | 22 |
2 files changed, 27 insertions, 8 deletions
diff --git a/server/lib/plugins/plugin-manager.ts b/server/lib/plugins/plugin-manager.ts index c64ca60aa..38336bcc6 100644 --- a/server/lib/plugins/plugin-manager.ts +++ b/server/lib/plugins/plugin-manager.ts | |||
@@ -21,7 +21,8 @@ import { ClientHtml } from '../client-html' | |||
21 | import { PluginTranslation } from '../../../shared/models/plugins/plugin-translation.model' | 21 | import { PluginTranslation } from '../../../shared/models/plugins/plugin-translation.model' |
22 | import { RegisterHelpersStore } from './register-helpers-store' | 22 | import { RegisterHelpersStore } from './register-helpers-store' |
23 | import { RegisterServerHookOptions } from '@shared/models/plugins/register-server-hook.model' | 23 | import { RegisterServerHookOptions } from '@shared/models/plugins/register-server-hook.model' |
24 | import { MOAuthTokenUser } from '@server/typings/models' | 24 | import { MOAuthTokenUser, MUser } from '@server/typings/models' |
25 | import { RegisterServerAuthPassOptions, RegisterServerAuthExternalOptions } from '@shared/models/plugins/register-server-auth.model' | ||
25 | 26 | ||
26 | export interface RegisteredPlugin { | 27 | export interface RegisteredPlugin { |
27 | npmName: string | 28 | npmName: string |
@@ -133,14 +134,14 @@ export class PluginManager implements ServerHook { | |||
133 | return this.translations[locale] || {} | 134 | return this.translations[locale] || {} |
134 | } | 135 | } |
135 | 136 | ||
136 | onLogout (npmName: string, authName: string) { | 137 | onLogout (npmName: string, authName: string, user: MUser) { |
137 | const auth = this.getAuth(npmName, authName) | 138 | const auth = this.getAuth(npmName, authName) |
138 | 139 | ||
139 | if (auth?.onLogout) { | 140 | if (auth?.onLogout) { |
140 | logger.info('Running onLogout function from auth %s of plugin %s', authName, npmName) | 141 | logger.info('Running onLogout function from auth %s of plugin %s', authName, npmName) |
141 | 142 | ||
142 | try { | 143 | try { |
143 | auth.onLogout() | 144 | auth.onLogout(user) |
144 | } catch (err) { | 145 | } catch (err) { |
145 | logger.warn('Cannot run onLogout function from auth %s of plugin %s.', authName, npmName, { err }) | 146 | logger.warn('Cannot run onLogout function from auth %s of plugin %s.', authName, npmName, { err }) |
146 | } | 147 | } |
@@ -478,8 +479,10 @@ export class PluginManager implements ServerHook { | |||
478 | const plugin = this.getRegisteredPluginOrTheme(npmName) | 479 | const plugin = this.getRegisteredPluginOrTheme(npmName) |
479 | if (!plugin || plugin.type !== PluginType.PLUGIN) return null | 480 | if (!plugin || plugin.type !== PluginType.PLUGIN) return null |
480 | 481 | ||
481 | return plugin.registerHelpersStore.getIdAndPassAuths() | 482 | let auths: (RegisterServerAuthPassOptions | RegisterServerAuthExternalOptions)[] = plugin.registerHelpersStore.getIdAndPassAuths() |
482 | .find(a => a.authName === authName) | 483 | auths = auths.concat(plugin.registerHelpersStore.getExternalAuths()) |
484 | |||
485 | return auths.find(a => a.authName === authName) | ||
483 | } | 486 | } |
484 | 487 | ||
485 | // ###################### Private getters ###################### | 488 | // ###################### Private getters ###################### |
diff --git a/server/lib/plugins/register-helpers-store.ts b/server/lib/plugins/register-helpers-store.ts index 277f2b687..151196bf1 100644 --- a/server/lib/plugins/register-helpers-store.ts +++ b/server/lib/plugins/register-helpers-store.ts | |||
@@ -1,5 +1,12 @@ | |||
1 | import * as express from 'express' | ||
1 | import { logger } from '@server/helpers/logger' | 2 | import { logger } from '@server/helpers/logger' |
2 | import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PLAYLIST_PRIVACIES, VIDEO_PRIVACIES } from '@server/initializers/constants' | 3 | import { |
4 | VIDEO_CATEGORIES, | ||
5 | VIDEO_LANGUAGES, | ||
6 | VIDEO_LICENCES, | ||
7 | VIDEO_PLAYLIST_PRIVACIES, | ||
8 | VIDEO_PRIVACIES | ||
9 | } from '@server/initializers/constants' | ||
3 | import { onExternalUserAuthenticated } from '@server/lib/auth' | 10 | import { onExternalUserAuthenticated } from '@server/lib/auth' |
4 | import { PluginModel } from '@server/models/server/plugin' | 11 | import { PluginModel } from '@server/models/server/plugin' |
5 | import { RegisterServerOptions } from '@server/typings/plugins' | 12 | import { RegisterServerOptions } from '@server/typings/plugins' |
@@ -10,11 +17,15 @@ import { PluginVideoCategoryManager } from '@shared/models/plugins/plugin-video- | |||
10 | import { PluginVideoLanguageManager } from '@shared/models/plugins/plugin-video-language-manager.model' | 17 | import { PluginVideoLanguageManager } from '@shared/models/plugins/plugin-video-language-manager.model' |
11 | import { PluginVideoLicenceManager } from '@shared/models/plugins/plugin-video-licence-manager.model' | 18 | import { PluginVideoLicenceManager } from '@shared/models/plugins/plugin-video-licence-manager.model' |
12 | import { PluginVideoPrivacyManager } from '@shared/models/plugins/plugin-video-privacy-manager.model' | 19 | import { PluginVideoPrivacyManager } from '@shared/models/plugins/plugin-video-privacy-manager.model' |
13 | import { RegisterServerAuthExternalOptions, RegisterServerAuthExternalResult, RegisterServerAuthPassOptions, RegisterServerExternalAuthenticatedResult } from '@shared/models/plugins/register-server-auth.model' | 20 | import { |
21 | RegisterServerAuthExternalOptions, | ||
22 | RegisterServerAuthExternalResult, | ||
23 | RegisterServerAuthPassOptions, | ||
24 | RegisterServerExternalAuthenticatedResult | ||
25 | } from '@shared/models/plugins/register-server-auth.model' | ||
14 | import { RegisterServerHookOptions } from '@shared/models/plugins/register-server-hook.model' | 26 | import { RegisterServerHookOptions } from '@shared/models/plugins/register-server-hook.model' |
15 | import { RegisterServerSettingOptions } from '@shared/models/plugins/register-server-setting.model' | 27 | import { RegisterServerSettingOptions } from '@shared/models/plugins/register-server-setting.model' |
16 | import { serverHookObject } from '@shared/models/plugins/server-hook.model' | 28 | import { serverHookObject } from '@shared/models/plugins/server-hook.model' |
17 | import * as express from 'express' | ||
18 | import { buildPluginHelpers } from './plugin-helpers' | 29 | import { buildPluginHelpers } from './plugin-helpers' |
19 | 30 | ||
20 | type AlterableVideoConstant = 'language' | 'licence' | 'category' | 'privacy' | 'playlistPrivacy' | 31 | type AlterableVideoConstant = 'language' | 'licence' | 'category' | 'privacy' | 'playlistPrivacy' |
@@ -174,6 +185,11 @@ export class RegisterHelpersStore { | |||
174 | const self = this | 185 | const self = this |
175 | 186 | ||
176 | return (options: RegisterServerAuthExternalOptions) => { | 187 | return (options: RegisterServerAuthExternalOptions) => { |
188 | if (!options.authName || !options.onAuthRequest || typeof options.onAuthRequest !== 'function') { | ||
189 | logger.error('Cannot register auth plugin %s: authName of getWeight or login are not valid.', this.npmName) | ||
190 | return | ||
191 | } | ||
192 | |||
177 | this.externalAuths.push(options) | 193 | this.externalAuths.push(options) |
178 | 194 | ||
179 | return { | 195 | return { |