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

Can't get full response in callback

Open ivan-ionin opened this issue 8 years ago • 3 comments

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 } ));

ivan-ionin avatar May 04 '17 07:05 ivan-ionin

Have you tried this?

passport.use('oAuth2', new OAuth2Strategy({
authorizationURL: '...',
tokenURL: '...',
clientID: '...',
clientSecret: '...',
callbackURL: '...'
passReqToCallback: true
}, function(req, accessToken, refreshToken, params, profile, done) {}));

joh-klein avatar May 31 '17 09:05 joh-klein

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);

codestorycooked avatar Oct 24 '17 07:10 codestorycooked

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.

aocenas avatar Nov 05 '18 13:11 aocenas