node-oauth2-server icon indicating copy to clipboard operation
node-oauth2-server copied to clipboard

[Question] Retrieving the username (Express version)

Open avrono opened this issue 7 years ago • 5 comments

Is there anyway to get back the username once a user is authenticated ? I.e can you suggest a mechanism to do this ?

avrono avatar Oct 17 '16 14:10 avrono

Provided you're talking about v3 and not v2 (the version published on npm):

You should be able to access the client and user objects through the result from OAuth2Server#authenticate:

oauthServer.authenticate(req, res)
  .then((token) => {
    console.log(token.client);
    console.log(token.user);
  });

Or with express-oauth-server:

app.get('/', oauthServer.authenticate(), (req, res, next) => {
  let token = res.locals.oauth.token;
  console.log(token.client);
  console.log(token.user);
});

If you're using v2 I can't really help you since I've never used it.

maxtruxa avatar Oct 17 '16 17:10 maxtruxa

Many thanks !

avrono avatar Oct 18 '16 13:10 avrono

This should really be documented somewhere.

@ruimarinho: Could you add this to whichever v3 milestone you're targeting for documentation?

maxtruxa avatar Oct 18 '16 14:10 maxtruxa

@maxtruxa Will do

mjsalinger avatar Oct 19 '16 20:10 mjsalinger

This is now documented here.

maxtruxa avatar Mar 10 '17 00:03 maxtruxa