mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
feat: grant plugins the ability to specify options to the SSO handler
... to be handled in the plugin itself (overriding the passport prototype's authorizationParams method) + new hook filter:auth.options
This commit is contained in:
@@ -98,13 +98,21 @@ Auth.reloadRoutes = async function (params) {
|
||||
loginStrategies = loginStrategies || [];
|
||||
loginStrategies.forEach(function (strategy) {
|
||||
if (strategy.url) {
|
||||
router.get(strategy.url, Auth.middleware.applyCSRF, function (req, res, next) {
|
||||
req.session.ssoState = req.csrfToken && req.csrfToken();
|
||||
passport.authenticate(strategy.name, {
|
||||
router.get(strategy.url, Auth.middleware.applyCSRF, async function (req, res, next) {
|
||||
let opts = {
|
||||
scope: strategy.scope,
|
||||
prompt: strategy.prompt || undefined,
|
||||
state: strategy.checkState ? req.session.ssoState : undefined,
|
||||
})(req, res, next);
|
||||
};
|
||||
|
||||
if (strategy.checkState) {
|
||||
req.session.ssoState = req.csrfToken && req.csrfToken();
|
||||
opts.state = req.session.ssoState;
|
||||
}
|
||||
|
||||
// Allow SSO plugins to override/append options (for use in passport prototype authorizationParams)
|
||||
({ opts } = await plugins.hooks.fire('filter:auth.options', { req, res, opts }));
|
||||
|
||||
passport.authenticate(strategy.name, opts)(req, res, next);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user