oauthjs / express-oauth-server

Complete, compliant and well tested module for implementing an OAuth2 Server/Provider with express in node.js
MIT License
483 stars 384 forks source link

Get loggedin User #16

Open yairvillarp opened 8 years ago

yairvillarp commented 8 years ago

Sorry to ask, but i've been having a problem to finish setup, i had to remove de validation of the response instance in the authenticate() middleware, since i haven't been able to set the response before passing to the middleware.

now another question, how can I get the user that is logged in??

manjeshpv commented 8 years ago

I failed to found proper solution, so temporary https://github.com/manjeshpv/node-oauth2-server-implementation/blob/master/components/oauth/authenticate.js#L43

Update 1: Found Solution working with 3.0.0-b2 authenticate().then(token => { req.user = token; next() }) https://github.com/manjeshpv/node-oauth2-server-implementation/blob/67e4e7e601e704a44803245e1a1e3e3255cbc9de/components/oauth/authenticate.js#L29

sandinosaso commented 7 years ago

How about:

app.get('/api/secureSite', app.oauth.authenticate(),
  (req, res, next) => { 
    console.log(res.locals.oauth.token);
    next();
  },
  HERE_YOUR_ACTUAL_MIDELWARE_HANDLER_FOR_THE_ENDPOINT
);