diff options
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/api/config.ts | 56 | ||||
-rw-r--r-- | server/controllers/plugins.ts | 20 |
2 files changed, 64 insertions, 12 deletions
diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts index 06fe30371..e8941bc73 100644 --- a/server/controllers/api/config.ts +++ b/server/controllers/api/config.ts | |||
@@ -1,22 +1,22 @@ | |||
1 | import { Hooks } from '@server/lib/plugins/hooks' | ||
1 | import * as express from 'express' | 2 | import * as express from 'express' |
3 | import { remove, writeJSON } from 'fs-extra' | ||
2 | import { snakeCase } from 'lodash' | 4 | import { snakeCase } from 'lodash' |
3 | import { ServerConfig, UserRight } from '../../../shared' | 5 | import validator from 'validator' |
6 | import { RegisteredExternalAuthConfig, RegisteredIdAndPassAuthConfig, ServerConfig, UserRight } from '../../../shared' | ||
4 | import { About } from '../../../shared/models/server/about.model' | 7 | import { About } from '../../../shared/models/server/about.model' |
5 | import { CustomConfig } from '../../../shared/models/server/custom-config.model' | 8 | import { CustomConfig } from '../../../shared/models/server/custom-config.model' |
6 | import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/signup' | ||
7 | import { CONSTRAINTS_FIELDS, DEFAULT_THEME_NAME, PEERTUBE_VERSION } from '../../initializers/constants' | ||
8 | import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../middlewares' | ||
9 | import { customConfigUpdateValidator } from '../../middlewares/validators/config' | ||
10 | import { ClientHtml } from '../../lib/client-html' | ||
11 | import { auditLoggerFactory, CustomConfigAuditView, getAuditIdFromRes } from '../../helpers/audit-logger' | 9 | import { auditLoggerFactory, CustomConfigAuditView, getAuditIdFromRes } from '../../helpers/audit-logger' |
12 | import { remove, writeJSON } from 'fs-extra' | ||
13 | import { getServerCommit } from '../../helpers/utils' | ||
14 | import validator from 'validator' | ||
15 | import { objectConverter } from '../../helpers/core-utils' | 10 | import { objectConverter } from '../../helpers/core-utils' |
11 | import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/signup' | ||
12 | import { getServerCommit } from '../../helpers/utils' | ||
16 | import { CONFIG, isEmailEnabled, reloadConfig } from '../../initializers/config' | 13 | import { CONFIG, isEmailEnabled, reloadConfig } from '../../initializers/config' |
14 | import { CONSTRAINTS_FIELDS, DEFAULT_THEME_NAME, PEERTUBE_VERSION } from '../../initializers/constants' | ||
15 | import { ClientHtml } from '../../lib/client-html' | ||
17 | import { PluginManager } from '../../lib/plugins/plugin-manager' | 16 | import { PluginManager } from '../../lib/plugins/plugin-manager' |
18 | import { getThemeOrDefault } from '../../lib/plugins/theme-utils' | 17 | import { getThemeOrDefault } from '../../lib/plugins/theme-utils' |
19 | import { Hooks } from '@server/lib/plugins/hooks' | 18 | import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../middlewares' |
19 | import { customConfigUpdateValidator } from '../../middlewares/validators/config' | ||
20 | 20 | ||
21 | const configRouter = express.Router() | 21 | const configRouter = express.Router() |
22 | 22 | ||
@@ -79,7 +79,9 @@ async function getConfig (req: express.Request, res: express.Response) { | |||
79 | } | 79 | } |
80 | }, | 80 | }, |
81 | plugin: { | 81 | plugin: { |
82 | registered: getRegisteredPlugins() | 82 | registered: getRegisteredPlugins(), |
83 | registeredExternalAuths: getExternalAuthsPlugins(), | ||
84 | registeredIdAndPassAuths: getIdAndPassAuthPlugins() | ||
83 | }, | 85 | }, |
84 | theme: { | 86 | theme: { |
85 | registered: getRegisteredThemes(), | 87 | registered: getRegisteredThemes(), |
@@ -269,6 +271,38 @@ function getRegisteredPlugins () { | |||
269 | })) | 271 | })) |
270 | } | 272 | } |
271 | 273 | ||
274 | function getIdAndPassAuthPlugins () { | ||
275 | const result: RegisteredIdAndPassAuthConfig[] = [] | ||
276 | |||
277 | for (const p of PluginManager.Instance.getIdAndPassAuths()) { | ||
278 | for (const auth of p.idAndPassAuths) { | ||
279 | result.push({ | ||
280 | npmName: p.npmName, | ||
281 | authName: auth.authName, | ||
282 | weight: auth.getWeight() | ||
283 | }) | ||
284 | } | ||
285 | } | ||
286 | |||
287 | return result | ||
288 | } | ||
289 | |||
290 | function getExternalAuthsPlugins () { | ||
291 | const result: RegisteredExternalAuthConfig[] = [] | ||
292 | |||
293 | for (const p of PluginManager.Instance.getExternalAuths()) { | ||
294 | for (const auth of p.externalAuths) { | ||
295 | result.push({ | ||
296 | npmName: p.npmName, | ||
297 | authName: auth.authName, | ||
298 | authDisplayName: auth.authDisplayName | ||
299 | }) | ||
300 | } | ||
301 | } | ||
302 | |||
303 | return result | ||
304 | } | ||
305 | |||
272 | // --------------------------------------------------------------------------- | 306 | // --------------------------------------------------------------------------- |
273 | 307 | ||
274 | export { | 308 | export { |
diff --git a/server/controllers/plugins.ts b/server/controllers/plugins.ts index 1fc49b646..f12e1c0f5 100644 --- a/server/controllers/plugins.ts +++ b/server/controllers/plugins.ts | |||
@@ -2,11 +2,12 @@ import * as express from 'express' | |||
2 | import { PLUGIN_GLOBAL_CSS_PATH } from '../initializers/constants' | 2 | import { PLUGIN_GLOBAL_CSS_PATH } from '../initializers/constants' |
3 | import { join } from 'path' | 3 | import { join } from 'path' |
4 | import { PluginManager, RegisteredPlugin } from '../lib/plugins/plugin-manager' | 4 | import { PluginManager, RegisteredPlugin } from '../lib/plugins/plugin-manager' |
5 | import { getPluginValidator, pluginStaticDirectoryValidator } from '../middlewares/validators/plugins' | 5 | import { getPluginValidator, pluginStaticDirectoryValidator, getExternalAuthValidator } from '../middlewares/validators/plugins' |
6 | import { serveThemeCSSValidator } from '../middlewares/validators/themes' | 6 | import { serveThemeCSSValidator } from '../middlewares/validators/themes' |
7 | import { PluginType } from '../../shared/models/plugins/plugin.type' | 7 | import { PluginType } from '../../shared/models/plugins/plugin.type' |
8 | import { isTestInstance } from '../helpers/core-utils' | 8 | import { isTestInstance } from '../helpers/core-utils' |
9 | import { getCompleteLocale, is18nLocale } from '../../shared/models/i18n' | 9 | import { getCompleteLocale, is18nLocale } from '../../shared/models/i18n' |
10 | import { logger } from '@server/helpers/logger' | ||
10 | 11 | ||
11 | const sendFileOptions = { | 12 | const sendFileOptions = { |
12 | maxAge: '30 days', | 13 | maxAge: '30 days', |
@@ -23,6 +24,12 @@ pluginsRouter.get('/plugins/translations/:locale.json', | |||
23 | getPluginTranslations | 24 | getPluginTranslations |
24 | ) | 25 | ) |
25 | 26 | ||
27 | pluginsRouter.get('/plugins/:pluginName/:pluginVersion/auth/:authName', | ||
28 | getPluginValidator(PluginType.PLUGIN), | ||
29 | getExternalAuthValidator, | ||
30 | handleAuthInPlugin | ||
31 | ) | ||
32 | |||
26 | pluginsRouter.get('/plugins/:pluginName/:pluginVersion/static/:staticEndpoint(*)', | 33 | pluginsRouter.get('/plugins/:pluginName/:pluginVersion/static/:staticEndpoint(*)', |
27 | getPluginValidator(PluginType.PLUGIN), | 34 | getPluginValidator(PluginType.PLUGIN), |
28 | pluginStaticDirectoryValidator, | 35 | pluginStaticDirectoryValidator, |
@@ -134,3 +141,14 @@ function serveThemeCSSDirectory (req: express.Request, res: express.Response) { | |||
134 | 141 | ||
135 | return res.sendFile(join(plugin.path, staticEndpoint), sendFileOptions) | 142 | return res.sendFile(join(plugin.path, staticEndpoint), sendFileOptions) |
136 | } | 143 | } |
144 | |||
145 | function handleAuthInPlugin (req: express.Request, res: express.Response) { | ||
146 | const authOptions = res.locals.externalAuth | ||
147 | |||
148 | try { | ||
149 | logger.debug('Forwarding auth plugin request in %s of plugin %s.', authOptions.authName, res.locals.registeredPlugin.npmName) | ||
150 | authOptions.onAuthRequest(req, res) | ||
151 | } catch (err) { | ||
152 | logger.error('Forward request error in auth %s of plugin %s.', authOptions.authName, res.locals.registeredPlugin.npmName) | ||
153 | } | ||
154 | } | ||