manjeshpv / node-oauth2-server-implementation

Using oauth2-server: 3.0.0-b2 & Supports MongoDB, MySQL, PostgreSQL, MSSQL & SQLite
216 stars 103 forks source link

Suggestion for authenticate handler override #6

Open joeauty opened 7 years ago

joeauty commented 7 years ago

Hello,

It took me some time to grasp the concepts behind the authorize flow, and overriding the authenticate handler. There are numerous threads about this in the node-oauth2-server project, as I'm sure you are aware. I think even if your example included this commented out, this might be helpful?

Something like this?

oauth.authorize(request, response, {
      authenticateHandler: {
        handle: function(req, res) {
          if (req.body.userId) {
            // return full user object if necessary, otherwise just the ID
            return req.body.userId;
          }
          else {
            // redirect to login form
          }
        }
      }
    })
    .then(function(success) {
      console.log("SUCCESS", success);
      cb(false, success);
    })
    .catch(function(err) {
      console.log("AUTH ERR", err);
      cb(err);
    })
manjeshpv commented 7 years ago

Hi can you create a pr.