Update to support redirect back to previous url after signin
This commit is contained in:
parent
ac087f0e90
commit
7ea56c78a2
1 changed files with 43 additions and 36 deletions
79
app.js
79
app.js
|
@ -252,87 +252,94 @@ app.post("/temp", urlencodedParser, function (req, res) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function setReturnToFromReferer(req) {
|
||||||
|
var referer = req.get('referer');
|
||||||
|
if (!req.session) req.session = {};
|
||||||
|
req.session.returnTo = referer;
|
||||||
|
}
|
||||||
|
|
||||||
//facebook auth
|
//facebook auth
|
||||||
if (config.facebook) {
|
if (config.facebook) {
|
||||||
app.get('/auth/facebook',
|
app.get('/auth/facebook', function (req, res, next) {
|
||||||
passport.authenticate('facebook'));
|
setReturnToFromReferer(req);
|
||||||
|
passport.authenticate('facebook')(req, res, next);
|
||||||
|
});
|
||||||
//facebook auth callback
|
//facebook auth callback
|
||||||
app.get('/auth/facebook/callback',
|
app.get('/auth/facebook/callback',
|
||||||
passport.authenticate('facebook', {
|
passport.authenticate('facebook', {
|
||||||
|
successReturnToOrRedirect: config.serverurl + '/',
|
||||||
failureRedirect: config.serverurl + '/'
|
failureRedirect: config.serverurl + '/'
|
||||||
}),
|
}));
|
||||||
function (req, res) {
|
|
||||||
res.redirect(config.serverurl + '/');
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
//twitter auth
|
//twitter auth
|
||||||
if (config.twitter) {
|
if (config.twitter) {
|
||||||
app.get('/auth/twitter',
|
app.get('/auth/twitter', function (req, res, next) {
|
||||||
passport.authenticate('twitter'));
|
setReturnToFromReferer(req);
|
||||||
|
passport.authenticate('twitter')(req, res, next);
|
||||||
|
});
|
||||||
//twitter auth callback
|
//twitter auth callback
|
||||||
app.get('/auth/twitter/callback',
|
app.get('/auth/twitter/callback',
|
||||||
passport.authenticate('twitter', {
|
passport.authenticate('twitter', {
|
||||||
|
successReturnToOrRedirect: config.serverurl + '/',
|
||||||
failureRedirect: config.serverurl + '/'
|
failureRedirect: config.serverurl + '/'
|
||||||
}),
|
}));
|
||||||
function (req, res) {
|
|
||||||
res.redirect(config.serverurl + '/');
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
//github auth
|
//github auth
|
||||||
if (config.github) {
|
if (config.github) {
|
||||||
app.get('/auth/github',
|
app.get('/auth/github', function (req, res, next) {
|
||||||
passport.authenticate('github'));
|
setReturnToFromReferer(req);
|
||||||
|
passport.authenticate('github')(req, res, next);
|
||||||
|
});
|
||||||
//github auth callback
|
//github auth callback
|
||||||
app.get('/auth/github/callback',
|
app.get('/auth/github/callback',
|
||||||
passport.authenticate('github', {
|
passport.authenticate('github', {
|
||||||
|
successReturnToOrRedirect: config.serverurl + '/',
|
||||||
failureRedirect: config.serverurl + '/'
|
failureRedirect: config.serverurl + '/'
|
||||||
}),
|
}));
|
||||||
function (req, res) {
|
|
||||||
res.redirect(config.serverurl + '/');
|
|
||||||
});
|
|
||||||
//github callback actions
|
//github callback actions
|
||||||
app.get('/auth/github/callback/:noteId/:action', response.githubActions);
|
app.get('/auth/github/callback/:noteId/:action', response.githubActions);
|
||||||
}
|
}
|
||||||
//gitlab auth
|
//gitlab auth
|
||||||
if (config.gitlab) {
|
if (config.gitlab) {
|
||||||
app.get('/auth/gitlab',
|
app.get('/auth/gitlab', function (req, res, next) {
|
||||||
passport.authenticate('gitlab'));
|
setReturnToFromReferer(req);
|
||||||
|
passport.authenticate('gitlab')(req, res, next);
|
||||||
|
});
|
||||||
//gitlab auth callback
|
//gitlab auth callback
|
||||||
app.get('/auth/gitlab/callback',
|
app.get('/auth/gitlab/callback',
|
||||||
passport.authenticate('gitlab', {
|
passport.authenticate('gitlab', {
|
||||||
|
successReturnToOrRedirect: config.serverurl + '/',
|
||||||
failureRedirect: config.serverurl + '/'
|
failureRedirect: config.serverurl + '/'
|
||||||
}),
|
}));
|
||||||
function (req, res) {
|
|
||||||
res.redirect(config.serverurl + '/');
|
|
||||||
});
|
|
||||||
//gitlab callback actions
|
//gitlab callback actions
|
||||||
app.get('/auth/gitlab/callback/:noteId/:action', response.gitlabActions);
|
app.get('/auth/gitlab/callback/:noteId/:action', response.gitlabActions);
|
||||||
}
|
}
|
||||||
//dropbox auth
|
//dropbox auth
|
||||||
if (config.dropbox) {
|
if (config.dropbox) {
|
||||||
app.get('/auth/dropbox',
|
app.get('/auth/dropbox', function (req, res, next) {
|
||||||
passport.authenticate('dropbox-oauth2'));
|
setReturnToFromReferer(req);
|
||||||
|
passport.authenticate('dropbox-oauth2')(req, res, next);
|
||||||
|
});
|
||||||
//dropbox auth callback
|
//dropbox auth callback
|
||||||
app.get('/auth/dropbox/callback',
|
app.get('/auth/dropbox/callback',
|
||||||
passport.authenticate('dropbox-oauth2', {
|
passport.authenticate('dropbox-oauth2', {
|
||||||
|
successReturnToOrRedirect: config.serverurl + '/',
|
||||||
failureRedirect: config.serverurl + '/'
|
failureRedirect: config.serverurl + '/'
|
||||||
}),
|
}));
|
||||||
function (req, res) {
|
|
||||||
res.redirect(config.serverurl + '/');
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
//google auth
|
//google auth
|
||||||
if (config.google) {
|
if (config.google) {
|
||||||
app.get('/auth/google',
|
app.get('/auth/google', function (req, res, next) {
|
||||||
passport.authenticate('google', { scope: ['profile'] }));
|
setReturnToFromReferer(req);
|
||||||
|
passport.authenticate('google', { scope: ['profile'] })(req, res, next);
|
||||||
|
});
|
||||||
//google auth callback
|
//google auth callback
|
||||||
app.get('/auth/google/callback',
|
app.get('/auth/google/callback',
|
||||||
passport.authenticate('google', {
|
passport.authenticate('google', {
|
||||||
|
successReturnToOrRedirect: config.serverurl + '/',
|
||||||
failureRedirect: config.serverurl + '/'
|
failureRedirect: config.serverurl + '/'
|
||||||
}),
|
}));
|
||||||
function (req, res) {
|
|
||||||
res.redirect(config.serverurl + '/');
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
//logout
|
//logout
|
||||||
app.get('/logout', function (req, res) {
|
app.get('/logout', function (req, res) {
|
||||||
|
|
Loading…
Reference in a new issue