-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix iframe fallback when RT is not found in cache (#6599)
It seems this fallback behavior was missed in the transition from v2 to v3. When the RT cannot be found in the cache we should try to fallback to the iframe flow. Also includes minor refactor to make the code more readable and remove some unnecessary work.
- Loading branch information
Showing
5 changed files
with
100 additions
and
71 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@azure-msal-browser-6d9ef336-f49e-47ba-9191-05676f55c887.json
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "patch", | ||
"comment": "Fix iframe fallback when RT is not found in cache", | ||
"packageName": "@azure/msal-browser", | ||
"email": "[email protected]", | ||
"dependentChangeType": "patch" | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3461,6 +3461,52 @@ describe("PublicClientApplication.ts Class Unit Tests", () => { | |
expect(silentIframeSpy.calledOnce).toBe(true); | ||
}); | ||
|
||
it("Calls SilentIframeClient.acquireToken and returns its response if no RT is cached", async () => { | ||
const testAccount: AccountInfo = { | ||
homeAccountId: TEST_DATA_CLIENT_INFO.TEST_HOME_ACCOUNT_ID, | ||
localAccountId: TEST_DATA_CLIENT_INFO.TEST_UID, | ||
environment: "login.windows.net", | ||
tenantId: "3338040d-6c67-4c5b-b112-36a304b66dad", | ||
username: "[email protected]", | ||
}; | ||
const testTokenResponse: AuthenticationResult = { | ||
authority: TEST_CONFIG.validAuthority, | ||
uniqueId: testAccount.localAccountId, | ||
tenantId: testAccount.tenantId, | ||
scopes: TEST_CONFIG.DEFAULT_SCOPES, | ||
idToken: "test-idToken", | ||
idTokenClaims: {}, | ||
accessToken: "test-accessToken", | ||
fromCache: false, | ||
correlationId: RANDOM_TEST_GUID, | ||
expiresOn: new Date(Date.now() + 3600000), | ||
account: testAccount, | ||
tokenType: AuthenticationScheme.BEARER, | ||
}; | ||
const silentCacheSpy = sinon | ||
.stub(SilentCacheClient.prototype, "acquireToken") | ||
.rejects("Expired"); | ||
const silentRefreshSpy = sinon | ||
.stub(SilentRefreshClient.prototype, "acquireToken") | ||
.rejects( | ||
createInteractionRequiredAuthError( | ||
InteractionRequiredAuthErrorCodes.noTokensFound | ||
) | ||
); | ||
const silentIframeSpy = sinon | ||
.stub(SilentIframeClient.prototype, "acquireToken") | ||
.resolves(testTokenResponse); | ||
|
||
const response = await pca.acquireTokenSilent({ | ||
scopes: ["openid"], | ||
account: testAccount, | ||
}); | ||
expect(response).toEqual(testTokenResponse); | ||
expect(silentCacheSpy.calledOnce).toBe(true); | ||
expect(silentRefreshSpy.calledOnce).toBe(true); | ||
expect(silentIframeSpy.calledOnce).toBe(true); | ||
}); | ||
|
||
it("makes one network request with multiple parallel silent requests with same request", async () => { | ||
const testServerTokenResponse = { | ||
token_type: TEST_CONFIG.TOKEN_TYPE_BEARER, | ||
|