Removing returnTo setting from referer in all other authentication sources

Signed-off-by: Ralph Krimmel <rkrimme1@gwdg.de>
This commit is contained in:
Ralph Krimmel 2019-11-28 12:25:59 +01:00
parent e0a8872742
commit 3fb3ca54e9
12 changed files with 8 additions and 28 deletions

View file

@ -4,7 +4,7 @@ const Router = require('express').Router
const passport = require('passport')
const DropboxStrategy = require('passport-dropbox-oauth2').Strategy
const config = require('../../../config')
const { setReturnToFromReferer, passportGeneralCallback } = require('../utils')
const { passportGeneralCallback } = require('../utils')
let dropboxAuth = module.exports = Router()
@ -16,7 +16,6 @@ passport.use(new DropboxStrategy({
}, passportGeneralCallback))
dropboxAuth.get('/auth/dropbox', function (req, res, next) {
setReturnToFromReferer(req)
passport.authenticate('dropbox-oauth2')(req, res, next)
})

View file

@ -7,7 +7,6 @@ const LocalStrategy = require('passport-local').Strategy
const config = require('../../../config')
const models = require('../../../models')
const logger = require('../../../logger')
const { setReturnToFromReferer } = require('../utils')
const { urlencodedParser } = require('../../utils')
const errors = require('../../../errors')
@ -71,7 +70,6 @@ if (config.allowEmailRegister) {
emailAuth.post('/login', urlencodedParser, function (req, res, next) {
if (!req.body.email || !req.body.password) return errors.errorBadRequest(res)
if (!validator.isEmail(req.body.email)) return errors.errorBadRequest(res)
setReturnToFromReferer(req)
passport.authenticate('local', {
successReturnToOrRedirect: config.serverURL + '/',
failureRedirect: config.serverURL + '/',

View file

@ -5,7 +5,7 @@ const passport = require('passport')
const FacebookStrategy = require('passport-facebook').Strategy
const config = require('../../../config')
const { setReturnToFromReferer, passportGeneralCallback } = require('../utils')
const { passportGeneralCallback } = require('../utils')
let facebookAuth = module.exports = Router()
@ -16,7 +16,6 @@ passport.use(new FacebookStrategy({
}, passportGeneralCallback))
facebookAuth.get('/auth/facebook', function (req, res, next) {
setReturnToFromReferer(req)
passport.authenticate('facebook')(req, res, next)
})

View file

@ -5,7 +5,7 @@ const passport = require('passport')
const GithubStrategy = require('passport-github').Strategy
const config = require('../../../config')
const response = require('../../../response')
const { setReturnToFromReferer, passportGeneralCallback } = require('../utils')
const { passportGeneralCallback } = require('../utils')
let githubAuth = module.exports = Router()
@ -16,7 +16,6 @@ passport.use(new GithubStrategy({
}, passportGeneralCallback))
githubAuth.get('/auth/github', function (req, res, next) {
setReturnToFromReferer(req)
passport.authenticate('github')(req, res, next)
})

View file

@ -5,7 +5,7 @@ const passport = require('passport')
const GitlabStrategy = require('passport-gitlab2').Strategy
const config = require('../../../config')
const response = require('../../../response')
const { setReturnToFromReferer, passportGeneralCallback } = require('../utils')
const { passportGeneralCallback } = require('../utils')
let gitlabAuth = module.exports = Router()
@ -18,7 +18,6 @@ passport.use(new GitlabStrategy({
}, passportGeneralCallback))
gitlabAuth.get('/auth/gitlab', function (req, res, next) {
setReturnToFromReferer(req)
passport.authenticate('gitlab')(req, res, next)
})

View file

@ -4,7 +4,7 @@ const Router = require('express').Router
const passport = require('passport')
var GoogleStrategy = require('passport-google-oauth20').Strategy
const config = require('../../../config')
const { setReturnToFromReferer, passportGeneralCallback } = require('../utils')
const { passportGeneralCallback } = require('../utils')
let googleAuth = module.exports = Router()
@ -16,7 +16,6 @@ passport.use(new GoogleStrategy({
}, passportGeneralCallback))
googleAuth.get('/auth/google', function (req, res, next) {
setReturnToFromReferer(req)
passport.authenticate('google', { scope: ['profile'] })(req, res, next)
})
// google auth callback

View file

@ -6,7 +6,6 @@ const LDAPStrategy = require('passport-ldapauth')
const config = require('../../../config')
const models = require('../../../models')
const logger = require('../../../logger')
const { setReturnToFromReferer } = require('../utils')
const { urlencodedParser } = require('../../utils')
const errors = require('../../../errors')
@ -82,7 +81,6 @@ passport.use(new LDAPStrategy({
ldapAuth.post('/auth/ldap', urlencodedParser, function (req, res, next) {
if (!req.body.username || !req.body.password) return errors.errorBadRequest(res)
setReturnToFromReferer(req)
passport.authenticate('ldapauth', {
successReturnToOrRedirect: config.serverURL + '/',
failureRedirect: config.serverURL + '/',

View file

@ -5,7 +5,7 @@ const passport = require('passport')
const Mattermost = require('mattermost')
const OAuthStrategy = require('passport-oauth2').Strategy
const config = require('../../../config')
const { setReturnToFromReferer, passportGeneralCallback } = require('../utils')
const { passportGeneralCallback } = require('../utils')
const mattermost = new Mattermost.Client()
@ -36,7 +36,6 @@ mattermostStrategy.userProfile = (accessToken, done) => {
passport.use(mattermostStrategy)
mattermostAuth.get('/auth/mattermost', function (req, res, next) {
setReturnToFromReferer(req)
passport.authenticate('oauth2')(req, res, next)
})

View file

@ -4,7 +4,7 @@ const Router = require('express').Router
const passport = require('passport')
const { Strategy, InternalOAuthError } = require('passport-oauth2')
const config = require('../../../config')
const { setReturnToFromReferer, passportGeneralCallback } = require('../utils')
const { passportGeneralCallback } = require('../utils')
let oauth2Auth = module.exports = Router()
@ -93,7 +93,6 @@ passport.use(new OAuth2CustomStrategy({
}, passportGeneralCallback))
oauth2Auth.get('/auth/oauth2', function (req, res, next) {
setReturnToFromReferer(req)
passport.authenticate('oauth2')(req, res, next)
})

View file

@ -7,7 +7,6 @@ const config = require('../../../config')
const models = require('../../../models')
const logger = require('../../../logger')
const { urlencodedParser } = require('../../utils')
const { setReturnToFromReferer } = require('../utils')
let openIDAuth = module.exports = Router()
@ -48,7 +47,6 @@ passport.use(new OpenIDStrategy({
}))
openIDAuth.post('/auth/openid', urlencodedParser, function (req, res, next) {
setReturnToFromReferer(req)
passport.authenticate('openid')(req, res, next)
})

View file

@ -5,7 +5,7 @@ const passport = require('passport')
const TwitterStrategy = require('passport-twitter').Strategy
const config = require('../../../config')
const { setReturnToFromReferer, passportGeneralCallback } = require('../utils')
const { passportGeneralCallback } = require('../utils')
let twitterAuth = module.exports = Router()
@ -16,7 +16,6 @@ passport.use(new TwitterStrategy({
}, passportGeneralCallback))
twitterAuth.get('/auth/twitter', function (req, res, next) {
setReturnToFromReferer(req)
passport.authenticate('twitter')(req, res, next)
})

View file

@ -3,12 +3,6 @@
const models = require('../../models')
const logger = require('../../logger')
exports.setReturnToFromReferer = function setReturnToFromReferer (req) {
var referer = req.get('referer')
if (!req.session) req.session = {}
req.session.returnTo = referer
}
exports.passportGeneralCallback = function callback (accessToken, refreshToken, profile, done) {
var stringifiedProfile = JSON.stringify(profile)
models.User.findOrCreate({