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

Callback doesn't work?

Open archasek opened this issue 7 years ago • 4 comments

Hi :)

passport.use('oauth2-login', new OAuth2Strategy(
    {
        authorizationURL: '...',
        tokenURL: '...',
        clientID: '...',
        clientSecret: '...',
        callbackURL: 'http://.../active-directory/success',
        passReqToCallback: true
    },
    function (req, accessToken, refreshToken, params, profile, cb) {
        console.log(11112322222); // -> this isn't logged to the console at all and I don't have ability to get user details from DB

        return cb(null, 'test')
    }
));
const oAuthAuthentication = passport.authenticate('oauth2-login');

router.get('/active-directory', oAuthAuthentication);
router.get('/active-directory/success', activeDirectorySuccess, redirectToHomepage);


function activeDirectorySuccess (req, res, next) {
    console.log('AD login success', req.query.code); // -> this works well

    return next();
}

Any idea? Thanks :)

archasek avatar Jul 19 '17 14:07 archasek

same here

lukedesu avatar Aug 19 '17 05:08 lukedesu

+1 same here

vaurelios avatar Oct 03 '17 02:10 vaurelios

any updates on this?

DhrubajitPC avatar Jan 12 '18 08:01 DhrubajitPC

Same here

Edit:

I solved it this way:

let oauth2 = new OAuth2Strategy({
    authorizationURL: protocol + '://' + base + '/auth/oauth2/authorize',
    tokenURL: protocol + '://' + base + '/auth/oauth2/token',
    clientID: '123',
    clientSecret: 'secret',
    callbackURL: protocol + '://' + base + '/auth/oauth2/callback',
    passReqToCallback: true
  }, (req, accessToken, refreshToken, profile, done) => {
    console.log('acc', accessToken)
    done(null, {
      accessToken,
      refreshToken,
      profile
    })
  })
passport.use('oauth2', oauth2)
app.all('/auth/oauth2/token', (req, res) => {
    // THIS TRIGGERS THE CALLBACK, DO WHAT YOU WANT ->
    oauth2._verify(
      req, 'access_token', 'refresh_token', {
        profile: '...'
      }, (err, user, info) => {
        if (err) return err
        if (!user) return null
        return info
      }
    )
    res.send({
      access_token: req.body.code,
      expires_in: 3600, // one hour (seconds)
      refresh_token: 'refresh_token'
    })
  })

steffanhalv avatar Dec 28 '18 14:12 steffanhalv