Open sarankup opened 9 years ago
Same here. Google Console settings are correct, works in Production but not in development.
Please provide more details. Error messages and stack traces are helpful when debugging issues.
Sorry, just realized that:
500 TokenError at Strategy.OAuth2Strategy.parseErrorResponse (app/node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/passport-oauth2/lib/strategy.js:298:12)
at Strategy.OAuth2Strategy._createOAuthError (app/node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/passport-oauth2/lib/strategy.js:345:16)
at app/node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/passport-oauth2/lib/strategy.js:171:43
at app/node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/passport-oauth2/node_modules/oauth/lib/oauth2.js:177:18
at passBackControl (app/node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/passport-oauth2/node_modules/oauth/lib/oauth2.js:124:9)
at IncomingMessage.<anonymous> (app/node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/passport-oauth2/node_modules/oauth/lib/oauth2.js:143:7)
at IncomingMessage.emit (events.js:129:20)
at _stream_readable.js:908:16
at process._tickCallback (node.js:355:11)
Hi,
For me, the google sign in page, opens and I click the account and then "Accept", again the page redirect to google login over and over again. Here goes the error message in console.
createCredentials() is deprecated, use tls.createSecureContext instead error happenTokenError
I'm using this with generator-angular-fullstack and am getting the "createCredentials is depreciated" error as well:
GET /auth/google 302 3ms - 0b
createCredentials() is deprecated, use tls.createSecureContext instead
InternalOAuthError: failed to fetch user profile
at /Users/arininsland/Sites/st_covers/backend/node_modules/passport-google-oauth/lib/passport-google-oauth/oauth2.js:88:28
at passBackControl (/Users/arininsland/Sites/st_covers/backend/node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/passport-oauth2/node_modules/oauth/lib/oauth2.js:124:9)
at IncomingMessage.<anonymous> (/Users/arininsland/Sites/st_covers/backend/node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/passport-oauth2/node_modules/oauth/lib/oauth2.js:143:7)
at IncomingMessage.emit (events.js:129:20)
at _stream_readable.js:908:16
at process._tickCallback (node.js:355:11)
GET /auth/google/callback?code=[obfuscated] 500 861ms - 718b
Edit: Never mind, this wasn't what was causing it to fail. It was not having the G+ API enabled in the Google API Console. This should probably be better signposted...
Just a note: my problem was solved.
Solution: I was using the same API credentials in both development and staging so Google wouldn't let me create a sign in on the same app (in it's eyes) from two locations.
Hi, Any update on this. It seems my problem is not resolved.
Does that mean, you want me to create a new app key in Google and assign?
In my case, I am just in the localhost, and not to place hosting now.
On Thu, May 14, 2015 at 3:33 AM, Alex Kahn notifications@github.com wrote:
Just a note: my problem was solved.
Solution: I was using the same API credentials in both development and staging so Google wouldn't let me create a sign in on the same app (in it's eyes) from two locations.
— Reply to this email directly or view it on GitHub https://github.com/jaredhanson/passport-google-oauth/issues/76#issuecomment-101829756 .
@sarankup If you already have a project in the API console you're using, go to https://console.developers.google.com, click "APIs & auth", "APIs", "Google+ API", "Enable API". Otherwise create a new project and do that.
@aendrew Thanks you saved me a bunch of headache. I didn't even think of doing that.
For anybody strugguling with it...
@alexkahn Could you elaborate a bit on how you solved this problem? Having a similar issue and I've tried all of the aforementioned steps but alas - no cigar.
@amejiarosario Thanks. But that's not working for me. Once I select & authorize , it shows 'ON' in top right, then I refresh, it shows OFF again. Am I missing anything ?
Same problem here. When I switch On it immediately turn Off after page refresh.
@OttlikG . What I found that it actually does not matter, if you turned on, you can be sure that it actually turned on. So that worked for me. And make sure that, your keys are trimmed (no space) when added into the code.
@imdadul Thanks, I came to the same solution one day ago.
It seems to be an issue with Google it self. Am also facing the issue, every time i turn on the "Authorize requests using OAuth 2.0:" option and i refresh the page it's turned off every time... I am pretty sure as when this stupid thing is turned on, Passport would work just fine
hey , i'm facing a similar problem and can not solve ot using the given solutions . let me know what changes i can make to debug the code
@aendrew hey , do you have idea what i am doing wrong here . at Strategy.OAuth2Strategy.parseErrorResponse (/home/hadoop/Documents/jobninja/node-oauth/new-oauth/node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/passport-oauth2/lib/strategy.js:298:12) at Strategy.OAuth2Strategy._createOAuthError (/home/hadoop/Documents/jobninja/node-oauth/new-oauth/node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/passport-oauth2/lib/strategy.js:345:16) at /home/hadoop/Documents/jobninja/node-oauth/new-oauth/node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/passport-oauth2/lib/strategy.js:171:43 at /home/hadoop/Documents/jobninja/node-oauth/new-oauth/node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/passport-oauth2/node_modules/oauth/lib/oauth2.js:177:18 at passBackControl (/home/hadoop/Documents/jobninja/node-oauth/new-oauth/node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/passport-oauth2/node_modules/oauth/lib/oauth2.js:123:9) at IncomingMessage. (/home/hadoop/Documents/jobninja/node-oauth/new-oauth/node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/passport-oauth2/node_modules/oauth/lib/oauth2.js:143:7) at IncomingMessage.emit (events.js:129:20) at _stream_readable.js:908:16 at process._tickCallback (node.js:355:11)
hey @alexkahn can you help me out here ?
@divneet @si74 My issue was just having one set of credentials for an app that I had in both development and production. All I had to do was set up some API credentials for both environments. If you aren't in that scenario then I don't really know what else to tell you.
hey @OttlikG can you help me out here ?
I just copied the key with an additional space and that caused the problem. I'm afraid of that I can't help you.
I get the same error when google calls my callback URL with a code
I'm using node 4.2.4 with express 4.13.3
"http:// domainname .com/login/google/callback?code=xxxxxxxxxxx"
TokenError
at Strategy.OAuth2Strategy.parseErrorResponse (/var/app/current/node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/passport-oauth2/lib/strategy.js:298:12)
at Strategy.OAuth2Strategy._createOAuthError (/var/app/current/node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/passport-oauth2/lib/strategy.js:345:16)
at /var/app/current/node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/passport-oauth2/lib/strategy.js:171:43
at /var/app/current/node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/passport-oauth2/node_modules/oauth/lib/oauth2.js:177:18
at passBackControl (/var/app/current/node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/passport-oauth2/node_modules/oauth/lib/oauth2.js:123:9)
at IncomingMessage.
I have tried all the workaround mentioned in this post but still getting the same error.
@amitbhatnagar try using everyauth ,since i wasn't able to work it out .
Make sure to check client-id and client-secret, wasted two hours on this, just because I assumed I did it right :expressionless:
@aendrew's solution worked for me. Thanks!
I meet a similar Error. The reason for my issue is that my server can't access google. 😭
In my case,
var GoogleStrategy = require( 'passport-google-oauth2' ).Strategy;
to
var GoogleStarategy = require('passport-google-oauth').OAuth2Strategy;
then it works.
I was an hour with the same error. My error was in callbackURL: 'auth/google/redirect'. The correct is callbackURL: '/auth/google/redirect'
Thank you guys for all you answers, just spent 4 hours trying to get the passportjs social authentication, I managed to get twitter,facebook and github authenticating, but I got stuck on google, as I was getting to the authentication page to then got some errors, until I found this page, I had not enabled Google + API, you really all served my day
I have done all of the above and I still get this error:
TokenError: Malformed auth code. at Strategy.OAuth2Strategy.parseErrorResponse (C:\nodeproj\packghome\node_modules\passport-oauth2\lib\strategy.js:329:12) at Strategy.OAuth2Strategy._createOAuthError (C:\nodeproj\packghome\node_modules\passport-oauth2\lib\strategy.js:376:16) at C:\nodeproj\packghome\node_modules\passport-oauth2\lib\strategy.js:166:45 at C:\nodeproj\packghome\node_modules\oauth\lib\oauth2.js:191:18 at passBackControl (C:\nodeproj\packghome\node_modules\oauth\lib\oauth2.js:132:9) at IncomingMessage.
(C:\nodeproj\packghome\node_modules\oauth\lib\oauth2.js:157:7) at emitNone (events.js:111:20) at IncomingMessage.emit (events.js:208:7) at endReadableNT (_stream_readable.js:1056:12) at _combinedTickCallback (internal/process/next_tick.js:138:11) at process._tickCallback (internal/process/next_tick.js:180:9)
I have the api enabled:
I get a code in the URL:
GoogleStrategy = require('passport-google-oauth20').Strategy
new GoogleStrategy({ clientID: keys.google.client_id, clientSecret: keys.google.client_secret, callbackURL: '/api/v0/auth/google/callback' },() => {});
Any help is appreciated
I had the exact same problem when deploying to heroku. Unauthorized token error means that your client secret is not entered correctly. Make sure it doesn't contain spaces when copying
Did anyone get client_secret is missing error. I am passing following object for google strategy
const GoogleStrategy = require('passport-google-oauth20').Strategy
passport.use ( new GoogleStrategy ({ clientID: keys.googleClientID, clent_secret: keys.googleClientSecret, callbackURL: '/auth/google/callback' }, (accessToken) => { console.log(accessToken) }))
Find the error details below.
TokenError: client_secret is missing.
at Strategy.OAuth2Strategy.parseErrorResponse (D:\Users\shasdr\Documents\FullStack\server\node_modules\passport-oauth2\lib\strategy.js:330:12)
at Strategy.OAuth2Strategy._createOAuthError (D:\Users\shasdr\Documents\FullStack\server\node_modules\passport-oauth2\lib\strategy.js:377:16)
at D:\Users\shasdr\Documents\FullStack\server\node_modules\passport-oauth2\lib\strategy.js:166:45
at D:\Users\shasdr\Documents\FullStack\server\node_modules\oauth\lib\oauth2.js:191:18
at passBackControl (D:\Users\shasdr\Documents\FullStack\server\node_modules\oauth\lib\oauth2.js:132:9)
at IncomingMessage.
unable to find fix. tried all the suggestions given in the above comment thread.
passport.use ( new GoogleStrategy ({ clientID: keys.googleClientID, clent_secret: keys.googleClientSecret, callbackURL: '/auth/google/callback' }, (accessToken) => { console.log(accessToken) }))
@shankywwww Not sure if you already solved this, however, It seems you're using client_secret
but it should be clientSecret
I am also getting the same error, have tried almost every suggestion present here, but none of them worked. Kindly help.
TokenError: Bad Request
at Strategy.OAuth2Strategy.parseErrorResponse (F:\Sambhav\Nodejs_Practice\Udemy\Node_React\node_modules\passport-oauth2\lib\strategy.js:329:12)
at Strategy.OAuth2Strategy._createOAuthError (F:\Sambhav\Nodejs_Practice\Udemy\Node_React\node_modules\passport-oauth2\lib\strategy.js:376:16)
at F:\Sambhav\Nodejs_Practice\Udemy\Node_React\node_modules\passport-oauth2\lib\strategy.js:166:45
at F:\Sambhav\Nodejs_Practice\Udemy\Node_React\node_modules\oauth\lib\oauth2.js:191:18
at passBackControl (F:\Sambhav\Nodejs_Practice\Udemy\Node_React\node_modules\oauth\lib\oauth2.js:132:9)
at IncomingMessage.
check the typo of clientID
and clientScrect
....That's what controlled my google+ API...
In my case:
passport.use(new GoogleStrategy({
clientID: config.google[env].appId,
clientSecret: config.google[env].clientSecret, // <- console.log(config.google[env].clientSecret === undefined)
callbackURL: `${(options.baseUrl || '')}/auth/google/callback`,
passReqToCallback: true,
}, (request, accessToken, refreshToken, profile, done) => { ... }));
Just a typo. Instead of config.google[env].clientSecret should have been config.google[env].appSecret
I am also getting the same error, have tried almost every suggestion present here, but none of them worked. Kindly help.
TokenError: Bad Request at Strategy.OAuth2Strategy.parseErrorResponse (F:\Sambhav\Nodejs_Practice\Udemy\Node_React\node_modules\passport-oauth2\lib\strategy.js:329:12) at Strategy.OAuth2Strategy._createOAuthError (F:\Sambhav\Nodejs_Practice\Udemy\Node_React\node_modules\passport-oauth2\lib\strategy.js:376:16) at F:\Sambhav\Nodejs_Practice\Udemy\Node_React\node_modules\passport-oauth2\lib\strategy.js:166:45 at F:\Sambhav\Nodejs_Practice\Udemy\Node_React\node_modules\oauth\lib\oauth2.js:191:18 at passBackControl (F:\Sambhav\Nodejs_Practice\Udemy\Node_React\node_modules\oauth\lib\oauth2.js:132:9) at IncomingMessage. (F:\Sambhav\Nodejs_Practice\Udemy\Node_React\node_modules\oauth\lib\oauth2.js:157:7) at emitNone (events.js:111:20) at IncomingMessage.emit (events.js:208:7) at endReadableNT (_stream_readable.js:1064:12) at _combinedTickCallback (internal/process/next_tick.js:138:11)
@SambhavS004 I'm getting the exact same error. Did you manage to fix it?
is there any single man to fix this error?
I am also getting the same error, have tried almost every suggestion present here, but none of them worked. Kindly help. TokenError: Bad Request at Strategy.OAuth2Strategy.parseErrorResponse (F:\Sambhav\Nodejs_Practice\Udemy\Node_React\node_modules\passport-oauth2\lib\strategy.js:329:12) at Strategy.OAuth2Strategy._createOAuthError (F:\Sambhav\Nodejs_Practice\Udemy\Node_React\node_modules\passport-oauth2\lib\strategy.js:376:16) at F:\Sambhav\Nodejs_Practice\Udemy\Node_React\node_modules\passport-oauth2\lib\strategy.js:166:45 at F:\Sambhav\Nodejs_Practice\Udemy\Node_React\node_modules\oauth\lib\oauth2.js:191:18 at passBackControl (F:\Sambhav\Nodejs_Practice\Udemy\Node_React\node_modules\oauth\lib\oauth2.js:132:9) at IncomingMessage. (F:\Sambhav\Nodejs_Practice\Udemy\Node_React\node_modules\oauth\lib\oauth2.js:157:7) at emitNone (events.js:111:20) at IncomingMessage.emit (events.js:208:7) at endReadableNT (_stream_readable.js:1064:12) at _combinedTickCallback (internal/process/next_tick.js:138:11)
@SambhavS004 I'm getting the exact same error. Did you manage to fix it?
In my case, I deleted the old credentials and created new one in the same google api project. I went to this https://console.developers.google.com/apis/credentials, selected the project, deleted the existed one OAuth 2.0 client ID and created new credentials with OAuth client ID then used the new clientID & clientSecret in my code. This is working fine for me.
I also encountered same issue while trying to invoke callback function,
_TokenError: Bad Request
at Strategy.OAuth2Strategy.parseErrorResponse (/Users/C5272869/Documents/node js/The Net Ninja/passportjs project/node_modules/passport-oauth2/lib/strategy.js:358:12)
at Strategy.OAuth2Strategy._createOAuthError (/Users/C5272869/Documents/node js/The Net Ninja/passportjs project/node_modules/passport-oauth2/lib/strategy.js:405:16)
at /Users/C5272869/Documents/node js/The Net Ninja/passportjs project/node_modules/passport-oauth2/lib/strategy.js:175:45
at /Users/C5272869/Documents/node js/The Net Ninja/passportjs project/node_modules/oauth/lib/oauth2.js:191:18
at passBackControl (/Users/C5272869/Documents/node js/The Net Ninja/passportjs project/node_modules/oauth/lib/oauth2.js:132:9)
at IncomingMessage.
Solution - Two solutions I found feasible which worked for me a. ``` passport.use(new GoogleStrategy({ //options for google strategy callbackURL: '/auth/google/redirect', //I forgot initial / before auth. clientID: keys.google.clientID, clientSecret: keys.google.clientSecret }, (accessToken, refreshToken, profile, done) => { //passport callback function console.log('--------- callback function fired ---------'); console.log(profile);
}))
b. credentials should be used wisely on different deployment platforms.
TokenError: Bad Request
at Strategy.OAuth2Strategy.parseErrorResponse (f:\Angular\node\oauth\node_modules\passport-oauth2\lib\strategy.js:358:12)
at Strategy.OAuth2Strategy._createOAuthError (f:\Angular\node\oauth\node_modules\passport-oauth2\lib\strategy.js:405:16)
at f:\Angular\node\oauth\node_modules\passport-oauth2\lib\strategy.js:175:45
at f:\Angular\node\oauth\node_modules\oauth\lib\oauth2.js:191:18
at passBackControl (f:\Angular\node\oauth\node_modules\oauth\lib\oauth2.js:132:9)
at IncomingMessage.
can anyone help me how to solve >?
This issue seems to be active since 2015. Any other strategy you guys started using instead of this for OAuth2 with google?
I found out that this way caused because of some kind of timeout
error for me. Mainly because I didn't call the done callback function passed from the strategy.
Passport.use(new GoogleStrategy({
clientID: '',
clientSecret: '',
callbackURL: "http://localhost:3400/auth/google/callback"
}, (accessToken , refreshToken, profile, done) => {
console.log(`${accessToken} -> access token`);
console.log(`${refreshToken} -> refresh token`);
// Store user's token in the db but with more security.
done(false, {strategy: 'google' , accessToken , refreshToken , ...profile});
})
);
Passport.serializeUser
and Passport.deserializeUser
functions alsoresetting the credentials like @sumanmahto mentioned worked for me.
Catch all errors...
exports.setup = () => {
passport.use(new GoogleStrategy({
clientID: config.client_id,
clientSecret: config.client_secret,
callbackURL: config.callback_uri
}, (accessToken, refreshToken, profile, done) => {
if (profile && profile._json && profile._json.email) {
return User.findOne({ email: profile._json.email }).exec().then(user => {
user.displayName = profile._json.name
user.photoURL = profile._json.picture
return user.save()
}).then(savedUser => done(null, savedUser)).catch(done)
} else return done()
}))
}
I am also getting the same error
TokenError: Bad Request
Please let me know if google sign in can be implemented without using passport
I encountered the same problem because I removed "return cb(err, user);" code as below works well: findOrCreate is from "mongoose-findorcreate"
passport.use(new GoogleStrategy({ clientID: process.env.ClientID, clientSecret: process.env.ClientKey, callbackURL: "xxxx" userProfileURL: "https://www.googleapis.com/oauth2/v3/userinfo" }, function(accessToken, refreshToken, profile, cb) { User.findOrCreate({ googleId: profile.id }, function(err, user) { return cb(err, user); ; }); } ));
Hey Guys! This Error have Best Solution:
Replace Following Code:
passport.use(new GoogleStrategy({ clientID: process.env.GOOGLE_CLIENT_ID, clientSecret: process.env.GOOGLE_CLIENT_SECRET, callbackURL: '/auth/google/callback' }, async (accessToken, refreshToken, profile, done) => { // Users full Profile by Google // console.log(profile) const newUser = { googleId: profile.id, displayName: profile.displayName, firstName: profile.name.givenName, lastName: profile.name.familyName, image: profile.photos[0].value }
console.log(newUser)
// you forgot this
done(null, null)
Hi,
I am using passport in total.js application in which all other oath works well including facebook, twitter. But when I try to login using Google account, I got "TokenError" as error.
Please advise how to solve.