connect-ensure-login
connect-ensure-login copied to clipboard
Do not manage to be automatically redirected to original URL
I'm using the following middleware for the oauth/authorize route:
app.get('/oauth/authorize',
login.ensureLoggedIn(),
server.authorize(function(clientId, redirectURI, done) {
Client.findOne({clientId: clientId}, function(err, client) {
if (err) { return done(err); }
if (!client) { return done(null, false); }
if (client.redirectURI != redirectURI) { return done(null, false); }
return done(null, client, client.redirectURI);
});
}),
server.errorHandler(),
function(req, res) {
res.render('dialog', { transactionID: req.oauth2.transactionID,
user: req.user,
client: req.oauth2.client
});
}
);
The connection URL is the following one:
http://localhost:1337/oauth/authorize?client_id=O3UTGRFNI1&response_type=code&redirect_uri=http://localhost:1339&scope=http://localhost:1337
When the user is not logged, he is redirected towards the login page but when he logs he is redirected towards the index page (instead of being redirected towards the above URL). Any idea why this is happening ? I've certainly missed something but I cannot figure out what (probably linked to returnTo).
I've also set up a complete example in the following question: http://stackoverflow.com/questions/25833533/secure-nodejs-app-with-oauth2-not-automatically-redirected-to-allow-deny-page
Did you ever resolve this issue? I'm having the same problem.
For anyone else running into this issue, it was indeed something very simple and is clearly in the docs:
app.post('/login', passport.authenticate('local', { successReturnToOrRedirect: '/', failureRedirect: '/login' }));
You need to give your passport route the successReturnToOrRedirect
parameter so that it knows what to do after you login.
Thanks a lot, I didn't got this.
@nodeit thanks
@nodeit thanks, that answer is gold.
Although the option is documented, it's not intuitive at all. successReturnToOrRedirect: '/'
might indicate a redirect to root rather than the original url.
I did this and noticed the user is logged in only after the third attempt... I removed the package and it worked well... How do i get around this? github.com/miracle0403/newsitemlm.git