Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InternalOAuthError: Failed to obtain access token #146

Open
akakum921 opened this issue Dec 26, 2021 · 3 comments
Open

InternalOAuthError: Failed to obtain access token #146

akakum921 opened this issue Dec 26, 2021 · 3 comments
Labels
question Request for help or support

Comments

@akakum921
Copy link

I am getting this error after choosing the google account for signing in
InternalOAuthError: Failed to obtain access token
at Strategy.OAuth2Strategy._createOAuthError (C:\Users\sairam\Desktop\nodews\codeial\node_modules\passport-oauth2\lib\strategy.js:423:17)
at C:\Users\sairam\Desktop\nodews\codeial\node_modules\passport-oauth2\lib\strategy.js:177:45
at C:\Users\sairam\Desktop\nodews\codeial\node_modules\oauth\lib\oauth2.js:191:18
at ClientRequest. (C:\Users\sairam\Desktop\nodews\codeial\node_modules\oauth\lib\oauth2.js:162:5)
at ClientRequest.emit (events.js:400:28)
at TLSSocket.socketErrorListener (_http_client.js:475:9)
at TLSSocket.emit (events.js:400:28)
at emitErrorNT (internal/streams/destroy.js:106:8)
at emitErrorCloseNT (internal/streams/destroy.js:74:3)
at processTicksAndRejections (internal/process/task_queues.js:82:21)

This is the passport google strategy
'
const passport = require('passport');
const googleStrategy = require('passport-google-oauth').OAuth2Strategy;
const crypto = require('crypto');

const User = require("../models/user");

//tell passport to use a new strategy for google login

passport.use(new googleStrategy({
clientID: GOOGLE_CLIENT_ID,
clientSecret: GOOGLE_SECRET,
callbackURL: 'http://localhost:8000/users/auth/google/callback',
},
function(accessToken, refreshToken, profile, done){
// find a user
User.findOne({email: profile.emails[0].value}).exec(function(err, user) {
if(err) {
console.log("Error in google strategy-passport", err);
return;
}
// console.log(accessToken);
console.log(profile);

    if(user) {
        // if found,set this user as a req.user
        return done(null, user);
    } 
    else {
        // if not found, create the user and set it as req.user
        User.create({
            name: profile.displayName,
            email: profile.emails[0].value,
            password: crypto.randomBytes(20).toString('hex'),
        }, function(err, user) {
    
            if (err) {
                console.log("Error in creating user google strategy-passport", err); return; }

            return done(null, user);
        }); 
    }
});

}

));

module.exports.passport; '

@jaredhanson
Copy link
Owner

Is your app configured with the correct client ID and secret?

@jaredhanson jaredhanson added the question Request for help or support label Dec 26, 2021
@akakum921
Copy link
Author

Yes, I cross checked it

@iohansson
Copy link

@jaredhanson seems that Google changed a lot in their auth flow https://developers.google.com/identity/protocols/oauth2/openid-connect#server-flow
The token url (https://oauth2.googleapis.com/token) doesn't match the one used in this strategy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Request for help or support
Projects
None yet
Development

No branches or pull requests

3 participants