diff options
author | Chocobozzz <me@florianbigard.com> | 2020-04-28 14:49:03 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-05-04 16:21:39 +0200 |
commit | 4a8d113b9b57d97ff13ad1608798eabca99643e4 (patch) | |
tree | 7c6e1ba86bff31680ba6c8ba4bd903b997592269 /server/middlewares | |
parent | 98813e69bccc568eff771cfcaf907ccdd82ce3f1 (diff) | |
download | PeerTube-4a8d113b9b57d97ff13ad1608798eabca99643e4.tar.gz PeerTube-4a8d113b9b57d97ff13ad1608798eabca99643e4.tar.zst PeerTube-4a8d113b9b57d97ff13ad1608798eabca99643e4.zip |
Begin support for external auths
Diffstat (limited to 'server/middlewares')
-rw-r--r-- | server/middlewares/validators/plugins.ts | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/server/middlewares/validators/plugins.ts b/server/middlewares/validators/plugins.ts index 65765f473..2cb49ec43 100644 --- a/server/middlewares/validators/plugins.ts +++ b/server/middlewares/validators/plugins.ts | |||
@@ -4,7 +4,7 @@ import { logger } from '../../helpers/logger' | |||
4 | import { areValidationErrors } from './utils' | 4 | import { areValidationErrors } from './utils' |
5 | import { isNpmPluginNameValid, isPluginNameValid, isPluginTypeValid, isPluginVersionValid } from '../../helpers/custom-validators/plugins' | 5 | import { isNpmPluginNameValid, isPluginNameValid, isPluginTypeValid, isPluginVersionValid } from '../../helpers/custom-validators/plugins' |
6 | import { PluginManager } from '../../lib/plugins/plugin-manager' | 6 | import { PluginManager } from '../../lib/plugins/plugin-manager' |
7 | import { isBooleanValid, isSafePath, toBooleanOrNull } from '../../helpers/custom-validators/misc' | 7 | import { isBooleanValid, isSafePath, toBooleanOrNull, exists } from '../../helpers/custom-validators/misc' |
8 | import { PluginModel } from '../../models/server/plugin' | 8 | import { PluginModel } from '../../models/server/plugin' |
9 | import { InstallOrUpdatePlugin } from '../../../shared/models/plugins/install-plugin.model' | 9 | import { InstallOrUpdatePlugin } from '../../../shared/models/plugins/install-plugin.model' |
10 | import { PluginType } from '../../../shared/models/plugins/plugin.type' | 10 | import { PluginType } from '../../../shared/models/plugins/plugin.type' |
@@ -40,6 +40,26 @@ const getPluginValidator = (pluginType: PluginType, withVersion = true) => { | |||
40 | ]) | 40 | ]) |
41 | } | 41 | } |
42 | 42 | ||
43 | const getExternalAuthValidator = [ | ||
44 | param('authName').custom(exists).withMessage('Should have a valid auth name'), | ||
45 | |||
46 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
47 | logger.debug('Checking getExternalAuthValidator parameters', { parameters: req.params }) | ||
48 | |||
49 | if (areValidationErrors(req, res)) return | ||
50 | |||
51 | const plugin = res.locals.registeredPlugin | ||
52 | if (!plugin.registerHelpersStore) return res.sendStatus(404) | ||
53 | |||
54 | const externalAuth = plugin.registerHelpersStore.getExternalAuths().find(a => a.authName === req.params.authName) | ||
55 | if (!externalAuth) return res.sendStatus(404) | ||
56 | |||
57 | res.locals.externalAuth = externalAuth | ||
58 | |||
59 | return next() | ||
60 | } | ||
61 | ] | ||
62 | |||
43 | const pluginStaticDirectoryValidator = [ | 63 | const pluginStaticDirectoryValidator = [ |
44 | param('staticEndpoint').custom(isSafePath).withMessage('Should have a valid static endpoint'), | 64 | param('staticEndpoint').custom(isSafePath).withMessage('Should have a valid static endpoint'), |
45 | 65 | ||
@@ -175,5 +195,6 @@ export { | |||
175 | listAvailablePluginsValidator, | 195 | listAvailablePluginsValidator, |
176 | existingPluginValidator, | 196 | existingPluginValidator, |
177 | installOrUpdatePluginValidator, | 197 | installOrUpdatePluginValidator, |
178 | listPluginsValidator | 198 | listPluginsValidator, |
199 | getExternalAuthValidator | ||
179 | } | 200 | } |