passport-oauth2 icon indicating copy to clipboard operation
passport-oauth2 copied to clipboard

Support userInfo endpoint

Open ThallesP opened this issue 2 years ago • 1 comments

Hi @jaredhanson, I see that the profile params are empty for me, would be possible to populate that with the userInfo endpoint?

Most of OAuth2 providers (keycloak for example) supports that endpoint.

I was thinking of something like this:

passport.use(new OAuth2Strategy({
    authorizationURL: 'https://www.example.com/oauth2/authorize',
    tokenURL: 'https://www.example.com/oauth2/token',
    userInfo: "https://www.example.com/oauth2/userinfo",
    clientID: EXAMPLE_CLIENT_ID,
    clientSecret: EXAMPLE_CLIENT_SECRET,
    callbackURL: "http://localhost:3000/auth/example/callback"
  },
  function(accessToken, refreshToken, profile, cb) {
    console.log(profile) // output: {<...>}
    User.findOrCreate({ exampleId: profile.id }, function (err, user) {
      return cb(err, user);
    });
  }
));

I would like to make a PR request if that's fine for you.

ThallesP avatar Oct 19 '23 20:10 ThallesP

@jaredhanson Hi! Any chances to add this functionality. We receive accessToken that can be pass to _oauth2.get() function like in google_auth20 package.

Niewdanka avatar May 16 '24 21:05 Niewdanka