oneblink / hapi-oauth2orize

A bridge between hapi and OAuth2orize
BSD 3-Clause "New" or "Revised" License
27 stars 17 forks source link

different signatures in oauth.authorize #10

Open midnightcodr opened 9 years ago

midnightcodr commented 9 years ago

Hello, In the example oauth.authorize is passed with two different signatures, the first one is (request, reply, function ... ) and the second one is (function ...), was that an error? Because when token() is called, the following error is raised: TypeError: Uncaught error: Cannot read property 'lazy' of undefined

at Object.internals.convertToExpress (/path/to/node_modules/hapi-oauth2orize/index.js:202:20)

function authorize(request, reply) {
  oauth.authorize(request, reply, function (req, res) {
    reply.view('oauth', {transactionID: req.oauth2.transactionID});
  }, function (clientID, redirect, done) {
    server.helpers.find('client', clientID, function (docs) {
      done(null, docs[0], docs[0].redirect_uri);
    });
  });
};

function decision(request, reply) {
    oauth.decision(request, reply);
};

function token(request, reply) {
  oauth.authorize(function (clientID, redirect, done) {
    done(null, clientID, redirect);
  });
};

Also I wonder if it's possible to include authentication in the example. Should I use hapi-auth-cookie to handle authentication with oauth2orize?

midnightcodr commented 9 years ago

I think I found the answer to my own question. The second oath.authorize should actually be oauth.token. I have forked this repo at https://github.com/midnightcodr/hapi-oauth2orize with a minor update to index.js and the example shown in README.md. This post https://hnryjms.github.io/2014/07/oauth2/ helped me a lot in figuring out the solution.

devinivy commented 8 years ago

Thanks! The docs need a lot of work, and we'd definitely take the help. Can you explain the change you made to index.js?