Begin support for external auths
This commit is contained in:
parent
98813e69bc
commit
4a8d113b9b
15 changed files with 397 additions and 175 deletions
|
@ -2,11 +2,12 @@ import * as express from 'express'
|
|||
import { PLUGIN_GLOBAL_CSS_PATH } from '../initializers/constants'
|
||||
import { join } from 'path'
|
||||
import { PluginManager, RegisteredPlugin } from '../lib/plugins/plugin-manager'
|
||||
import { getPluginValidator, pluginStaticDirectoryValidator } from '../middlewares/validators/plugins'
|
||||
import { getPluginValidator, pluginStaticDirectoryValidator, getExternalAuthValidator } from '../middlewares/validators/plugins'
|
||||
import { serveThemeCSSValidator } from '../middlewares/validators/themes'
|
||||
import { PluginType } from '../../shared/models/plugins/plugin.type'
|
||||
import { isTestInstance } from '../helpers/core-utils'
|
||||
import { getCompleteLocale, is18nLocale } from '../../shared/models/i18n'
|
||||
import { logger } from '@server/helpers/logger'
|
||||
|
||||
const sendFileOptions = {
|
||||
maxAge: '30 days',
|
||||
|
@ -23,6 +24,12 @@ pluginsRouter.get('/plugins/translations/:locale.json',
|
|||
getPluginTranslations
|
||||
)
|
||||
|
||||
pluginsRouter.get('/plugins/:pluginName/:pluginVersion/auth/:authName',
|
||||
getPluginValidator(PluginType.PLUGIN),
|
||||
getExternalAuthValidator,
|
||||
handleAuthInPlugin
|
||||
)
|
||||
|
||||
pluginsRouter.get('/plugins/:pluginName/:pluginVersion/static/:staticEndpoint(*)',
|
||||
getPluginValidator(PluginType.PLUGIN),
|
||||
pluginStaticDirectoryValidator,
|
||||
|
@ -134,3 +141,14 @@ function serveThemeCSSDirectory (req: express.Request, res: express.Response) {
|
|||
|
||||
return res.sendFile(join(plugin.path, staticEndpoint), sendFileOptions)
|
||||
}
|
||||
|
||||
function handleAuthInPlugin (req: express.Request, res: express.Response) {
|
||||
const authOptions = res.locals.externalAuth
|
||||
|
||||
try {
|
||||
logger.debug('Forwarding auth plugin request in %s of plugin %s.', authOptions.authName, res.locals.registeredPlugin.npmName)
|
||||
authOptions.onAuthRequest(req, res)
|
||||
} catch (err) {
|
||||
logger.error('Forward request error in auth %s of plugin %s.', authOptions.authName, res.locals.registeredPlugin.npmName)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue