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

(Task AB#1268089) | Defer token store unlock until token refresh response action occurs #168

Conversation

brettwellmanmbo
Copy link
Contributor

@brettwellmanmbo brettwellmanmbo commented Jan 31, 2024

This pull request includes (pick all that apply):

  • Bugfixes
  • New features
  • Breaking changes
  • Documentation updates
  • Unit tests
  • Other

Summary

The goal of this pull request is to ensure that during a token refresh, the token store lock stays engaged until after any token store I/O resulting from the outcome of the token refresh have occurred.

Presently the token store lock disengages immediately after a token refresh response is received but before any actions are taken on the token store (such as saving the new token to the token store). This, theoretically, could allow premature token store access before the outcome of the token refresh call has had a chance to propagate its result to the token store. If this were to occur, the premature access would result in the token store returning a token that was just burnt by the token refresh call, resulting in call failure due to either an access token that's no longer valid, or a refresh token that was just used.

Implementation

Move & split the disengagement of the token store lock from where it is now (executing immediately after receiving a refresh response), into two places:

  1. In the case of a token refresh success, the token store unluck now occurs directly after the new token is stored to the token store.
  2. In the case of a token refresh failure, the token store unlock now occurs directly after the previous token is purged from the token store.

Test Plan

Induce token refreshes in any client apps that consume this framework & ensure regular functionality is observed. I have been testing these changes in MBApp while hunting down a refresh token race condition and all

…after new token stored or old token deleted

Currently the token store unlock occurs directly after the token refresh call completes, but prior to the new token being stored or the old token being deleted.  In situations with a high volume of asynchronous calls occurring leading up to the token refresh flow initiating, a race condition can occur upon token store unlock whereby a subsequent token refresh call that was queued then immediately retrieves the previous refresh token from the unlocked token store before the new refresh token has had a chance to be written to the token store.
The resulting token refresh API call attempt using a burnt/no longer valid refresh token results in a 400 level error (e.g. 'invalid_grant' ) from the OAuth2 identity server.
…shared call

- Removed some `self` references
- Added comment
@brettwellmanmbo brettwellmanmbo merged commit 62ec0e6 into main Feb 2, 2024
1 check passed
@brettwellmanmbo brettwellmanmbo deleted the task/AB#1268089-delay-tokenstore-unlock-until-refresh-response-action-occurs branch February 2, 2024 22:43
@brettwellmanmbo brettwellmanmbo changed the title (Task AB#1268089) | [Token Refresh Flow] Defer token store unlock until refresh response action occurs (T AB#1268089) | Defer token store unlock until refresh response action occurs Feb 5, 2024
@brettwellmanmbo brettwellmanmbo changed the title (T AB#1268089) | Defer token store unlock until refresh response action occurs (Task AB#1268089) | Defer token store unlock until token refresh response action occurs Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants