fix(auth): update token provider auth config on reconfigure#14746
Open
anivar wants to merge 1 commit intoaws-amplify:mainfrom
Open
fix(auth): update token provider auth config on reconfigure#14746anivar wants to merge 1 commit intoaws-amplify:mainfrom
anivar wants to merge 1 commit intoaws-amplify:mainfrom
Conversation
When Amplify.configure() is called multiple times (e.g. to switch userPoolClientId for multi-tenant apps), the cognitoUserPoolsTokenProvider was not updated with the new auth config. This caused token refresh to use the stale userPoolClientId, failing with NotAuthorizedException. The fix adds cognitoUserPoolsTokenProvider.setAuthConfig() calls to the two reconfigure code paths that were missing them in initSingleton.ts. Closes aws-amplify#14620
🦋 Changeset detectedLatest commit: 12c8289 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Open
3 tasks
Contributor
Author
|
This also fixes #13707 (CognitoUserPoolsTokenProvider authTokenStore does not update keys with latest Auth config) — same root cause. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of changes
When
Amplify.configure()is called multiple times to switchuserPoolClientId(e.g. for multi-tenant apps), thecognitoUserPoolsTokenProviderwas not updated with the new auth config on subsequent calls. This causedfetchAuthSession({ forceRefresh: true })and internal token refresh to use the staleuserPoolClientId, failing withNotAuthorizedException.Root cause: In
initSingleton.ts,cognitoUserPoolsTokenProvider.setAuthConfig()was only called on the first configure path (when!Amplify.libraryOptions.Auth). The two reconfigure paths — with and withoutlibraryOptions— skipped it entirely.Fix: Added
cognitoUserPoolsTokenProvider.setAuthConfig(resolvedResourceConfig.Auth)to both reconfigure code paths. Two lines added, no structural changes.Issue #, if available
Closes #14620
Description of how you validated changes
setAuthConfigwas NOT called on reconfiguresetAuthConfigis called with updated config whenuserPoolClientIdchangesChecklist
yarn testpassesBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.