lucj / sails-oauth2-api

140 stars 34 forks source link

Not redirected to the Allow/deny page after login #6

Closed lucj closed 9 years ago

lucj commented 9 years ago

I have a problem with the Authorization Code Grant that I do not manage to solve.

Basically, This are the steps I follow:

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 ?

pawanrawal commented 9 years ago

@lucj Where you able to fix this ? I got this flow to work and could send a pull request some time over the weekend ?

lucj commented 9 years ago

Hi Pawan, This one should be fixed. Feel free to give it a try and let me know if this is still broken. Thanks a lot, Luc Le 3 sept. 2015 6:26 AM, "Pawan Rawal" notifications@github.com a écrit :

@lucj https://github.com/lucj Where you able to fix this ? I got this flow to work and could send a pull request some time over the weekend ?

— Reply to this email directly or view it on GitHub https://github.com/lucj/sails-oauth2-api/issues/6#issuecomment-137327768 .

pawanrawal commented 9 years ago

Hi , it does work though the code could be organized better. For examples routes for oauth endpoints are defined in oauth.js in config . Probably it would be better if they were defined in routes.js ? Do you plan to write test cases for this ? I could help with that.

lucj commented 9 years ago

Hi, I totally agree with you, code organisation could be enhanced. I'm not sure that defining those endpoints in config/routes.js is possible though but if you do manage to have this working, that would be great and much clearer. I'd really appreciate if you could help to write some test cases. Thanks Pawan.

On Thu, Sep 3, 2015 at 1:05 PM, Pawan Rawal notifications@github.com wrote:

Hi , it does work though the code could be organized better. For examples routes for oauth endpoints are defined in oauth.js in config . Probably it would be better if they were defined in routes.js ? Do you plan to write test cases for this ? I could help with that.

— Reply to this email directly or view it on GitHub https://github.com/lucj/sails-oauth2-api/issues/6#issuecomment-137408940 .

Luc Juggery - https://about.me/lucjuggery

pawanrawal commented 9 years ago

Hi lucj , I got a cleaner implementation to work with routes in route.js and better code organization.. Will share it with you when I cover the test suite. For my use case I am only implementing the Authorization Code Grant flow.

lucj commented 9 years ago

Excellent. Thanks for your help Pawan.

On Thu, Sep 3, 2015 at 1:22 PM, Pawan Rawal notifications@github.com wrote:

Hi lucj , I got a cleaner implementation to work with routes in route.js and better code organization.. Will share it with you when I cover the test suite. For my use case I am only implementing the Authorization Code Grant flow.

— Reply to this email directly or view it on GitHub https://github.com/lucj/sails-oauth2-api/issues/6#issuecomment-137411466 .

Luc Juggery - https://about.me/lucjuggery