I've set up a project to secure a sails application with OAuth2: https://github.com/lucj/sails-oauth2-api
I have a problem with the Authorization Code Grant that I do not manage to solve.
Basically, This are the steps I follow:
- run the sails app
- run the unTrustedClient (node untrustedClient.js within the example folder)
- from a web browser, I then issue the following URL:
http://localhost:1337/oauth/authorize?client_id=O3UTGRFNI1&response_type=code&redirect_uri=http://localhost:1339&scope=http://localhost:1337
Note: the value of the client_id is the one displayed for untrustedTestClient in the sails terminal when the application starts
This redirect me toward the 'login' page, which is fine.
https://dl.dropboxusercontent.com/u/2330187/login.png
But when I submit the credentials (me@gmail.com /password by default) I'm redirected towards /index and not toward the original URL (the one above).
https://dl.dropboxusercontent.com/u/2330187/index.png
I need to re-issue the URL above for the dialog page (the one with the Allow / Deny options) to be displayed.
https://dl.dropboxusercontent.com/u/2330187/allow_deny.png
I'm using 'connect-ensure-login' middleware.
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
});
}
);
How can I fix this so the redirection is done automatically once I enter the credentials ?