strongloop / loopback-component-oauth2

oAuth 2.0 server for LoopBack
http://www.strongloop.com
Other
62 stars 63 forks source link

Cannot get the access_token and always redirects me to the login page #58

Closed dyaa closed 6 years ago

dyaa commented 7 years ago

Steps to reproduce

I installed the module and i made the login view and the dialog view. here's my server.js configration

var options = {
    dataSource: app.dataSources.db, // Data source for oAuth2 metadata persistence
    loginPage: '/login', // The login page url
    loginPath: '/login', // The login form processing url
    decisionView: '/dialog'
};
oauth2.oAuth2Provider(
    app, // The app instance
    options // The options
);

and my routes

router.get('/login', function (req, res) {
    res.render('login');
});

router.get('/dialog', function (req, res) {
    res.render('dialog');
});

router.get('/protected',oauth2.authenticate(['/protected'], { session: false, scope: 'email' }), function(req, res){
    res.status(200).json({"status":"pong"}).send();
});

Expected result

The expected result is that when i try to authorize then login it must i think redirect me to the decisionView to approve and to get the access_token and the refresh_token after that, But when i'm trying to authorize like this http://0.0.0.0:3000/oauth/authorize?client_id=a72bc3c6f54bfd9fc1ca6d19c0e031b&response_type=token&redirect_uri=http://localhost:3000/auth/example/callback it's redirect me to the login view /login after the successful login it redirects me to /users/login with this JSON example

{
    "id": "dNBqjx4JixMJTVzKfPazakDj1uB22KmOUBAYTrSIpNNegrhCLKCuC89j9Hg5bKX",
    "ttl": 1209600,
    "created": "2017-01-27T09:59:29.666Z",
    "userId": 1
}

i tried manually go to the /dialog route and click on allow it redirect me again to the /login route.

Actual result (if bug)

The actual result it's always send me to the /login route.

Additional information (Node.js version, LoopBack version, etc)

NodeJS Version v6.9.4 Loopback version 1.0.0 (generator-loopback@2.2.0)

stale[bot] commented 7 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

lkappeler commented 7 years ago

I just run into the same issue. For me the solution form https://github.com/strongloop/loopback-component-oauth2/issues/67#issuecomment-305707365 worked fine and solved the issue. Some other potentional solutions can be found here https://stackoverflow.com/questions/16434893/node-express-passport-req-user-undefined

stale[bot] commented 6 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 6 years ago

This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.