passport-oauth2
passport-oauth2 copied to clipboard
Callback doesn't work?
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 :)
same here
+1 same here
any updates on this?
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'
})
})