-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
fix(auth): add inflightPromise in token orchestrator #13158
Conversation
} | ||
|
||
return new Promise<void>((resolve, _reject) => { | ||
addInflightPromise(resolve); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we remove the addInflightPromise()
call from attempCompleteOAuthFlow
then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah good point
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cognitoUserPoolsTokenProvider.setWaitForInflightOAuth
should be removed as well as its single use case is being replace by this. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're planning on hot-fixing this, should target release
branch
@@ -23,13 +23,23 @@ import { | |||
DeviceMetadata, | |||
TokenRefresher, | |||
} from './types'; | |||
import { oAuthStore } from '../utils/oauth'; | |||
import { addInflightPromise } from '../utils/oauth/inflightPromise'; | |||
|
|||
export class TokenOrchestrator implements AuthTokenOrchestrator { | |||
private authConfig?: AuthConfig; | |||
tokenStore?: AuthTokenStore; | |||
tokenRefresher?: TokenRefresher; | |||
waitForInflightOAuth: () => Promise<void> = async () => { | |||
// no-op |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Not a no-op anymore
Description of changes
The main issue is due to a race condition between
attemptCompleteOAuthFlow
andTokenOrchestrator.getTokens
Ideally when there is an inflight OAuth flow,
attemptCompleteOAuthFlow
should always be called first to register any upcoming async calls coming fromTokenOrchestrator.getTokens
. This behavior is consistent in React but the affected frameworks are bundled different.The fix at the moment is to check if
OAuth
is inflight directly from the TokenOrchestrator and add an inflight promise if so.Issue #, if available
Description of how you validated changes
Checklist
yarn test
passesBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.