mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-25 19:26:31 -05:00
Merge pull request #227 from foobarable/fix/saml
Fixing redirection after SAML login
This commit is contained in:
commit
9bd09805d4
13 changed files with 10 additions and 28 deletions
|
@ -6,6 +6,8 @@ module.exports = {
|
|||
if (req.user) {
|
||||
responseError(res, '403', 'Forbidden', 'oh no.')
|
||||
} else {
|
||||
if (!req.session) req.session = {}
|
||||
req.session.returnTo = req.originalUrl || config.serverUrl + '/'
|
||||
req.flash('error', 'You are not allowed to access this page. Maybe try logging in?')
|
||||
res.redirect(config.serverURL + '/')
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
|
||||
|
|
|
@ -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 + '/',
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 + '/',
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
|
||||
|
|
|
@ -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({
|
||||
|
|
Loading…
Reference in a new issue