-
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 uncaught exceptions in acquireTokenSilent (#7073)
A recent change to optimize parallel iframed calls resulted in a regression that logged an uncaught exception to the console in the event that a single iframed call was made and failed. This happened because the stored promise rejected and didn't have a catch handler registered because there is not a parallel call dependent on this promise. This PR resolves this issue by ensuring that the stored promise never rejects but rather resolves with a true/false indicating whether the call succeeded or failed. Fixes #7052
- Loading branch information
Showing
3 changed files
with
60 additions
and
21 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@azure-msal-browser-94058809-8f02-4078-bdc6-02ff59c54ae3.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 uncaught exceptions in acquireTokenSilent #7073", | ||
"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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4817,6 +4817,43 @@ describe("PublicClientApplication.ts Class Unit Tests", () => { | |
}); | ||
}); | ||
|
||
it("throws iframe error if iframe renewal throws", (done) => { | ||
const testAccount: AccountInfo = { | ||
homeAccountId: TEST_DATA_CLIENT_INFO.TEST_HOME_ACCOUNT_ID, | ||
localAccountId: TEST_DATA_CLIENT_INFO.TEST_UID, | ||
environment: "login.windows.net", | ||
tenantId: "testTenantId", | ||
username: "[email protected]", | ||
}; | ||
|
||
jest.spyOn( | ||
RefreshTokenClient.prototype, | ||
"acquireTokenByRefreshToken" | ||
).mockRejectedValue( | ||
createInteractionRequiredAuthError( | ||
InteractionRequiredAuthErrorCodes.refreshTokenExpired | ||
) | ||
); | ||
|
||
const testIframeError = new InteractionRequiredAuthError( | ||
"interaction_required", | ||
"interaction is required" | ||
); | ||
|
||
jest.spyOn( | ||
SilentIframeClient.prototype, | ||
"acquireToken" | ||
).mockRejectedValue(testIframeError); | ||
|
||
pca.acquireTokenSilent({ | ||
scopes: ["Scope1"], | ||
account: testAccount, | ||
}).catch((e) => { | ||
expect(e).toEqual(testIframeError); | ||
done(); | ||
}); | ||
}); | ||
|
||
it("Falls back to silent handler if thrown error is a refresh token expired error", async () => { | ||
const invalidGrantError: ServerError = new ServerError( | ||
"invalid_grant", | ||
|