express-oauth-server icon indicating copy to clipboard operation
express-oauth-server copied to clipboard

Get loggedin User

Open yairvillarp opened this issue 8 years ago • 2 comments

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??

yairvillarp avatar Apr 19 '16 12:04 yairvillarp

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

manjeshpv avatar May 15 '16 08:05 manjeshpv

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
);

sandinosaso avatar Sep 11 '17 18:09 sandinosaso