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

fix(auth): add inflightPromise in token orchestrator #13158

Closed

Conversation

israx
Copy link
Member

@israx israx commented Mar 21, 2024

Description of changes

The main issue is due to a race condition between attemptCompleteOAuthFlow and TokenOrchestrator.getTokens

Ideally when there is an inflight OAuth flow, attemptCompleteOAuthFlow should always be called first to register any upcoming async calls coming from TokenOrchestrator.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

  • PR description included
  • yarn test passes
  • Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

}

return new Promise<void>((resolve, _reject) => {
addInflightPromise(resolve);
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah good point

Copy link
Member

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. 👍

Copy link
Contributor

@jimblanc jimblanc left a 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
Copy link
Contributor

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

@israx israx closed this Mar 22, 2024
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.

3 participants