Can't get full response in callback
passport.use('oAuth2', new OAuth2Strategy( { authorizationURL: '...', tokenURL: '...', clientID: '...', clientSecret: '...', callbackURL: '...' }, function(accessToken, refreshToken, profile, done) { // Here i get arguments accessToken and refreshToken, // empty profile ({}) and cb done // but oauth lib got with access_token so much more params // [ // 'access_token', // 'expires_in', // 'refresh_expires_in', // 'refresh_token', // 'token_type', // 'id_token', // 'not-before-policy', // 'session_state' // ] // and i can't get their in this callback } ));
Have you tried this?
passport.use('oAuth2', new OAuth2Strategy({
authorizationURL: '...',
tokenURL: '...',
clientID: '...',
clientSecret: '...',
callbackURL: '...'
passReqToCallback: true
}, function(req, accessToken, refreshToken, params, profile, done) {}));
Hi, Please try this. This should work: let strategy = new OAuth2Strategy({ authorizationURL: this.configParams.authEndpoint, callbackURL: this.configParams.callbackUrl, clientID: this.configParams.clientId, clientSecret: this.configParams.clientSecret, passReqToCallback: true, tokenURL: URL
},
function (req, accessToken, refreshToken, params, profile, done) {
console.log('=================================================');
console.log('OAuth2Strategy callback');
console.log('accessToken=', accessToken);
console.log('refreshToken=', refreshToken);
console.log('profile=', profile);
console.log('=================================================');
console.log(params);
let user = {
accessToken: accessToken,
refreshToken: refreshToken
expires: expires_in
};
return done(null, user);
}
);
// Use Passport with OAuth strategy.
this.passport.use(Constants.PROVIDER, strategy);
The request does not really help as that is the browser request after redirect not the Oauth token response. There is a duplicate issue which is solved https://github.com/jaredhanson/passport-oauth2/issues/23.
TLDR: you have to supply callback with additional parameter (the code checks for callback arity):
function (accessToken, refreshToken, params, profile, done) {
or if you also want the request:
function (req, accessToken, refreshToken, params, profile, done) {
and then params will be your response data.