question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`node-oauth` throws intermittent InternalOAuthErrors on fast connections

See original GitHub issue

Hey all, I’m spinning up a new project using Passport and the Google OAuth 2.0 strategy, and I’ve spent the last day troubleshooting a particularly weird issue. Namely, when try to log in, locally, I get a InternalOAuthError the majority of the time, and occasionally get a successful login.

My coworker who’s on a slower connection, does not have this issue.

After much speelunking through the node-oauth codebase, I’ve found the issue here: https://github.com/ciaranj/node-oauth/blob/master/lib/oauth2.js#L124-L163

What’s happening is that for some requests, Google responds with an early close (eg: sends a no-content header and immediately closes the connection). node-oauth handles this cleanly by immediately triggering the callback (instead of waiting for an end event). However, when Google’s servers then perform a connection reset, an error event is triggered, and node-oauth naively calls the callback again resulting in an InternalOAuthError being thrown.

So, why post this bug here? node-oauth appears to be a dead project (the last commit was in 2017), and this bug is going to impact users of passport-google-oauth2 on fast connections. Hopefully by posting this issue here, other folks will be able to quickly diagnose it and find a workaround.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:6
  • Comments:12

github_iconTop GitHub Comments

5reactions
jaredonlinecommented, Sep 14, 2022

I just spent quite a bit of time trying to track down this error and bumping node-oath to 0.10.0 fixes it. Can we get a dependency update in passport-google-oauth2 to match?

1reaction
ciaranjcommented, Jul 22, 2022

node-oauth 0.10.0 now contains the aforementioned pull-requests.

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - InternalOAuthError: Failed to obtain access token
Basically, on faster connections, node-oauth receives ECONNRESET and triggers the provided callback twice. A quick way to fix this is to add ...
Read more >
openid-client - npm
openid-client is a server side OpenID Relying Party (RP, Client) implementation for Node.js runtime, supports passport. Implemented specs & ...
Read more >
Complete Guide to Multi-Provider OAuth 2 Authorization in ...
In this guide, we will take a look at how you can build a complete OAuth 2 authorization workflow in a nodejs application...
Read more >
Authorization Errors | Device Access - Google Developers
Quick reference. During the authorization process, Google OAuth may return an error. Use this guide to troubleshoot the most common errors ...
Read more >
How to implement OAuth 2.0 in Node.js - LogRocket Blog
Instead of throwing the Postgres connection pool object everywhere, we're going to centralize it in this file and export the function. It's ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found