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

feat: adds forceRefreshOnFailure flag, for refreshing token on error #790

Merged
merged 2 commits into from
Oct 14, 2019
Merged

feat: adds forceRefreshOnFailure flag, for refreshing token on error #790

merged 2 commits into from
Oct 14, 2019

Conversation

skeggse
Copy link
Contributor

@skeggse skeggse commented Sep 18, 2019

It's highly unlikely, but the expiry_date could be wrong, or the comparison in isTokenExpiring could fail due to an inaccurate system clock. As a further fallback behavior, some developers may wish to opt-in to attempting a refresh if Google's servers respond with a status code that may indicate the token has expired.

  • Tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added the cla: no This human has *not* signed the Contributor License Agreement. label Sep 18, 2019
@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: yes This human has signed the Contributor License Agreement. and removed cla: no This human has *not* signed the Contributor License Agreement. labels Sep 18, 2019
@bcoe
Copy link
Contributor

bcoe commented Sep 18, 2019

👋 @skeggse thanks for the contribution 👍 I have it on my plate this week to dig into why the heck refresh token logic sometimes fails, I'll get back to reviewing this once I've done a bit of a deep dive on the functionality.

@bcoe
Copy link
Contributor

bcoe commented Oct 8, 2019

@skeggse I addressed a major issue with our refresh logic here:

#794

Do you think that this functionality is still something folks might need? If so I might just call the feature alwaysRefresh, and we could use it to set forceReferesh to true when getting a token?

@skeggse
Copy link
Contributor Author

skeggse commented Oct 8, 2019

I think this is still useful, and would like to see a solution similar to this one that doesn't depend on local state (like the system clock). I'd also like to avoid refreshing unless we get a signal that the token may not be up to date, as our analysis indicates that multiple api clients refreshing the token can result in some of the access tokens being invalid - we've implemented a bunch of extra locking around the token refresh process to work around this.

@bcoe
Copy link
Contributor

bcoe commented Oct 8, 2019

@skeggse how would the locking be facilitated in this case, you'd only have one of your clients configured to refresh, and several with no eager refresh or alwaysLazyRefresh?

@skeggse
Copy link
Contributor Author

skeggse commented Oct 8, 2019

@bcoe we extend the OAuth2Client to override the refreshTokenNoCache method and wrap the functionality in a pessimistic lock. Any additional logic to attempt refreshes in other contexts simply folds into that extended functionality.

Funny enough, our solution actually fairly well mirrors the approach proposed by the OP of #41.

@bcoe
Copy link
Contributor

bcoe commented Oct 9, 2019

@skeggse, I'm open to this feature, but I don't quite understand the flag lazyRefresh, I might call it something like forceRefreshOnFailure?

@skeggse
Copy link
Contributor Author

skeggse commented Oct 9, 2019

Sounds good to me! The flag just means that we should refresh the token in lazy cases, but your flag is far clearer.

@skeggse skeggse changed the title Add alwaysLazyRefresh flag Add forceRefreshOnFailure flag Oct 9, 2019
It's highly unlikely, but the expiry_date could be wrong, or the
comparison in isTokenExpiring could fail due to an inaccurate system
clock. As a further fallback behavior, some developers may wish to opt-
in to attempting a refresh if Google's servers respond with a status
code that may indicate the token has expired.
Copy link
Contributor

@bcoe bcoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome, I'll work on landing this soon.

@bcoe bcoe added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 14, 2019
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 14, 2019
@bcoe bcoe added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 14, 2019
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 14, 2019
@bcoe bcoe added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 14, 2019
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 14, 2019
@codecov
Copy link

codecov bot commented Oct 14, 2019

Codecov Report

Merging #790 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #790      +/-   ##
==========================================
+ Coverage   84.52%   84.54%   +0.01%     
==========================================
  Files          17       17              
  Lines         950      951       +1     
  Branches      211      211              
==========================================
+ Hits          803      804       +1     
  Misses         87       87              
  Partials       60       60
Impacted Files Coverage Δ
src/auth/refreshclient.ts 88.57% <ø> (ø) ⬆️
src/auth/jwtclient.ts 88.5% <100%> (ø) ⬆️
src/auth/oauth2client.ts 82.78% <100%> (+0.05%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d0b7f8b...1f6c252. Read the comment docs.

@bcoe bcoe added the status: blocked Resolving the issue is dependent on other work. label Oct 14, 2019
@bcoe
Copy link
Contributor

bcoe commented Oct 14, 2019

@skeggse I want to use this later today as an example of how our release process works, it's not actually blocked by anything on your end 👍

@skeggse
Copy link
Contributor Author

skeggse commented Oct 14, 2019

@bcoe awesome, love it!

@bcoe bcoe removed the status: blocked Resolving the issue is dependent on other work. label Oct 14, 2019
@bcoe bcoe added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 14, 2019
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 14, 2019
@bcoe bcoe changed the title Add forceRefreshOnFailure flag feat: adds forceRefreshOnFailure flag, for refreshing token on error Oct 14, 2019
@SurferJeffAtGoogle SurferJeffAtGoogle merged commit 54cf477 into googleapis:master Oct 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants