-
-
Notifications
You must be signed in to change notification settings - Fork 153
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 0 #64
Comments
I tried this out. I don't get any errors related to the whole authentication flow (InternalOAuthError in this case). I do get the user profile information back, and see it logged to the console (via A few catch though, I had to fix a couple of non-trivial syntax errors, before being able to run successfully. And there was a slight issue serialising the user details here --> |
I have the same problem, have you fixed it? |
Hi, If you can post the exact error for more insight. |
InternalOAuthError: Failed to obtain access token |
Sorry for the late reply, really busy. Ok, so I'm unable to replicate this, I really can't seem to figure out what the issue is. Everything goes smoothly. Also, for my earlier issue where I said the user details was unable to be serialised,
I needed to pass the usernameField as an option for passport-local-mongoose plugin like so Continuing, this might be a little bit too much, but if you're up for it, you can debug the function where this fails. I was able to trace and pinpoint the exact function called for getting the accessToken, it's here, the oauth library in node_modules...that's where the actual request to google api is called over the network... basically /path/to/project/ In there, you can check that you're actually getting the |
I have this problem on the production:
No problem with localhost. Also added my domain to authorized origins and redirect urls. |
Hi @XiaohanZhong , Check this solution posted by @danyxudong. "I searched google a while, found a solution, and my test is ok, please check it in the below. 1st, please find your proxy on the internet explorer. My sample is http://192.168.23.4:999; 2nd, install "https-proxy-agent" node package in your project folder; $ npm install https-proxy-agent 3rd, write the code as below; const HttpsProxyAgent = require('https-proxy-agent'); const gStrategy = new GoogleStrategy({ passport.use(gStrategy); Reference: Github: #59 |
@wjj28 How does one "Find" their proxy on IE? Struggling with this also. Thanks in advance! |
Internet Explorer proxy settings:
|
I'm not sure if I'm wrong but as far as i understand, passport-google-oauth2 is not meant to deliver neither access token nor refresh token, and it has a very simple explanation.
So, finally the issue is not getting resolved adding openid, or email in the strategy scope, no matter what we put there apparently doesn't work because it only returns the "access token" and the user information. |
@wjj28 thanks for the solution, worked well for me! |
For me the problem was that the clientSecret was having a space in the end (copy past error). Very hard to spot since the redirects work well until the callback |
I have the same issue, same errors, no extra space at the end of clientSecret... I've been stuck with this for a while now.. |
@VoyageinStyle I had a similar issue. Found this nodejs/node#42116 issue in the node repo, downgraded to 16.3.0 and it worked like a charm without any errors. |
For anyone still struggling with this issue, there's a problem with the diff --git a/node_modules/oauth/lib/oauth2.js b/node_modules/oauth/lib/oauth2.js
index 77241c4..42dd372 100644
--- a/node_modules/oauth/lib/oauth2.js
+++ b/node_modules/oauth/lib/oauth2.js
@@ -158,6 +158,7 @@ exports.OAuth2.prototype._executeRequest= function( http_library, options, post_
});
});
request.on('error', function(e) {
+ if (callbackCalled) { return }
callbackCalled= true;
callback(e);
});
|
Many thanks, this solved the issue for me. I had to downgrade to node version 16.3.0. I'm on a Mac and using google chrome. |
Same problem but we don't have a |
reproduced with
|
I also experienced this exact error. In my case, the problem lied in the inability of the library to access profile data. It might be related to your internet connection, or your proxy settings. |
|
中国墙受害者特供,使用的VPN使用的不是http代理协议而是Sockets代理协议的方法,wjj28分享的方法有效。 Check this solution posted by @danyxudong. 1st, please find your proxy on the internet explorer. My sample is socks5://127.0.0.1:40008; Add HTTP_PROXY=socks5://127.0.0.1:40008 into the .env file in your project folder ( If there is no .env file, then create one). 2nd, install "socks-proxy-agent"、“dotenv” node packages in your project folder; $ npm install socks-proxy-agent dotenv 3rd, write the code as below; import { SocksProxyAgent } from 'socks-proxy-agent'; env.config(); const gStrategy = new GoogleStrategy({ clientID: process.env.CLIENT_ID, clientSecret: process.env.CLIENT_SECRET, callbackURL: "http://localhost:3000/auth/google/secrets", userProfileURL: "https://www.googleapis.com/oauth2/v3/userinfo" }, function(accessToken, refreshToken, profile, cb) { console.log(profile); User.findOrCreate({ googleId: profile.id }, function (err, user) { return cb(err, user); }); } ); const Agent = new SocksProxyAgent(process.env.SOCKS5_PROXY||"socks5://127.0.0.1:40008"); gStrategy._oauth2.setAgent(Agent); passport.use('google',gStrategy); Wish my solution works for you." Reference: Github: jaredhanson/passport-oauth2#59 |
After choosing the google account from the google page, the page redirect to my app but the process keep hanging then an error of " InternalOAuthError: Failed to obtain access token 0" was thrown, thus authentication process can not proceed.
1.launch the app
2.go to http://localhost:3000/login or http://localhost:3000/register route , both have the link to
/auth/google/ route
3. the route trigger the
passport.authenticate("google", { scope: ["https://www.googleapis.com/auth/userinfo.profile"] }));
4.redirect to the google page, then I choose my google account to login
5.the google page seems to try wait for response from local host,
6 an error of "InternalOAuthError: Failed to obtain access token 0" was thrown
I am just trying to login with google oauth2
Expected behavior
After choosing the google account from the google authentication page, I should be redirected to my app and an Access Token is retrieved from google
Actual behavior
After choosing the google account from google page, the process hanged then the error was thrown, it seems the Authoriazation Code is retrieved but the passport-google-oauth2 package faild to exchange the Access Token with the Authorization Code in hand, the package should exchange them automatically, but why is it not done?
Steps to reproduce
11.launch the app
2.go to http://localhost:3000/login or http://localhost:3000/register route , both have the link to
/auth/google/ route
3. the route trigger the
passport.authenticate("google", { scope: ["https://www.googleapis.com/auth/userinfo.profile"] }));
4.redirect to the google page, then I choose my google account to login
5.the google page seems to try wait for response from local host,
6 an error of "InternalOAuthError: Failed to obtain access token 0" was thrown
// Format code using Markdown code blocks
Environment
[email protected]
The text was updated successfully, but these errors were encountered: