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

Add early expiration of Access Token in cache #233

Merged
merged 2 commits into from
Oct 3, 2019

Conversation

B-Galati
Copy link
Contributor

@B-Galati B-Galati commented Oct 3, 2019

Description

Hello,

Problem: In my case the access token provided by Auth0 is valid for 30 seconds and from time to time I would have 401 when trying to call the resource server.

image

Proprosed solution: this PR expires the access token 5 seconds before it really expires so that we can be more sure
the access token used against the resource server is not expired by the time it reaches it.

Let me know what you think.

Testing

  • This change adds test coverage for new/changed/fixed functionality

Checklist

  • I have added documentation for new/changed functionality in this PR or in auth0.com/docs
  • All active GitHub checks for tests, formatting, and security are passing
  • The correct base branch is being used, if not master

@B-Galati B-Galati requested a review from a team October 3, 2019 13:45
@luisrudge
Copy link
Contributor

@B-Galati thanks for the PR. Can you clarify how are you using the getTokenSilently method? Are you calling it right before doing the API call? Or are you storing the token somewhere else etc?

Regarding your PR, 5s is not the best solution. If we decide to move forward with this, I think we need to use a percentage based approach. Something like Math.min(expiresIn, expTime) * 1000 * 0.8;, so when it gets to 80% of the expiration time. Can yo please do this change and write a test? Thanks!

@B-Galati
Copy link
Contributor Author

B-Galati commented Oct 3, 2019

@luisrudge Good idea! PR updated along with tests.

Can you clarify how are you using the getTokenSilently method? Are you calling it right before doing the API call? Or are you storing the token somewhere else etc?

That's exactly it, calling it right before doing the API call using the cache strategy provided by the library.

@luisrudge
Copy link
Contributor

Thank you so much for this PR!

@luisrudge luisrudge merged commit a09dd1c into auth0:master Oct 3, 2019
@B-Galati
Copy link
Contributor Author

B-Galati commented Oct 4, 2019

Thank you for the quick merge!

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

Successfully merging this pull request may close these issues.

2 participants