Skip to content

Commit 6a1c4a3

Browse files
chore(deps): Update oidc-client-ts to the latest version (#2746)
1 parent 158a62e commit 6a1c4a3

File tree

6 files changed

+13
-154
lines changed

6 files changed

+13
-154
lines changed

packages/internal/toolkit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"enc-utils": "^3.0.0",
1414
"ethers": "^6.13.4",
1515
"magic-sdk": "^29.0.5",
16-
"oidc-client-ts": "3.3.0"
16+
"oidc-client-ts": "3.4.1"
1717
},
1818
"devDependencies": {
1919
"@swc/core": "^1.3.36",

packages/passport/sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"jwt-decode": "^3.1.2",
2323
"localforage": "^1.10.0",
2424
"magic-sdk": "^29.0.5",
25-
"oidc-client-ts": "3.3.0",
25+
"oidc-client-ts": "3.4.1",
2626
"uuid": "^8.3.2"
2727
},
2828
"devDependencies": {

packages/passport/sdk/src/authManager.test.ts

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -237,90 +237,6 @@ describe('AuthManager', () => {
237237
});
238238
});
239239

240-
describe('popup closed detection', () => {
241-
let mockPopupRef: any;
242-
let mockSetInterval: jest.SpyInstance;
243-
let mockClearInterval: jest.SpyInstance;
244-
245-
beforeEach(() => {
246-
mockPopupRef = {
247-
closed: false,
248-
close: jest.fn(),
249-
};
250-
251-
// Override the global mock for these tests
252-
(window.open as jest.Mock).mockReturnValue(mockPopupRef);
253-
254-
mockSetInterval = jest.spyOn(global, 'setInterval');
255-
mockClearInterval = jest.spyOn(global, 'clearInterval');
256-
});
257-
258-
afterEach(() => {
259-
mockSetInterval.mockRestore();
260-
mockClearInterval.mockRestore();
261-
});
262-
263-
it('should reject with "Popup closed by user" when popup is closed during authentication', async () => {
264-
// Mock signinPopup to return a promise that never resolves (simulating long authentication)
265-
const signinPromise = new Promise<any>(() => {
266-
// Promise never resolves to simulate ongoing authentication
267-
});
268-
mockSigninPopup.mockReturnValue(signinPromise);
269-
270-
// Start the login process
271-
const loginPromise = authManager.login();
272-
273-
// Wait for the polling to be set up
274-
await new Promise((resolve) => {
275-
setTimeout(resolve, 10);
276-
});
277-
278-
// Verify polling was set up
279-
expect(mockSetInterval).toHaveBeenCalledWith(expect.any(Function), 500);
280-
281-
// Get the polling function and simulate popup being closed
282-
const pollingCallback = mockSetInterval.mock.calls[0][0];
283-
mockPopupRef.closed = true;
284-
pollingCallback(); // Manually trigger the polling callback
285-
286-
// Expect the login to reject with popup closed error
287-
await expect(loginPromise).rejects.toThrow('Popup closed by user');
288-
});
289-
290-
it('should clean up timer when user authentication completes successfully', async () => {
291-
mockSigninPopup.mockResolvedValue(mockOidcUser);
292-
293-
await authManager.login();
294-
295-
// Verify timer was cleared
296-
expect(mockClearInterval).toHaveBeenCalled();
297-
// Verify popup was closed
298-
expect(mockPopupRef.close).toHaveBeenCalled();
299-
});
300-
301-
it('should fall back to original behavior when popup reference is not available', async () => {
302-
// Mock window.open to return null (popup blocked or failed)
303-
(window.open as jest.Mock).mockReturnValue(null);
304-
mockSigninPopup.mockResolvedValue(mockOidcUser);
305-
306-
const result = await authManager.login();
307-
308-
expect(result).toEqual(mockUser);
309-
// Should not set up polling when no popup reference
310-
expect(mockSetInterval).not.toHaveBeenCalled();
311-
});
312-
313-
it('should use correct polling duration constant', async () => {
314-
const neverResolvingPromise = new Promise(() => { });
315-
mockSigninPopup.mockReturnValue(neverResolvingPromise);
316-
317-
authManager.login().catch(() => { }); // Ignore rejection for this test
318-
319-
// Verify the polling interval uses the correct constant (500ms)
320-
expect(mockSetInterval).toHaveBeenCalledWith(expect.any(Function), 500);
321-
});
322-
});
323-
324240
describe('when the user has registered for imx', () => {
325241
it('should populate the imx object', async () => {
326242
mockSigninPopup.mockResolvedValue(mockOidcUser);

packages/passport/sdk/src/authManager.ts

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ import ConfirmationOverlay from './overlay/confirmationOverlay';
3232
import { LocalForageAsyncStorage } from './storage/LocalForageAsyncStorage';
3333
import { EmbeddedLoginPrompt } from './confirmation';
3434

35-
const LOGIN_POPUP_CLOSED_POLLING_DURATION = 500;
36-
3735
const formUrlEncodedHeader = {
3836
headers: {
3937
'Content-Type': 'application/x-www-form-urlencoded',
@@ -259,44 +257,14 @@ export default class AuthManager {
259257
const signinPopup = async () => {
260258
const extraQueryParams = this.buildExtraQueryParams(anonymousId, directLoginOptionsToUse, imPassportTraceId);
261259

262-
const userPromise = this.userManager.signinPopup({
260+
return this.userManager.signinPopup({
263261
extraQueryParams,
264262
popupWindowFeatures: {
265263
width: 410,
266264
height: 450,
267265
},
268266
popupWindowTarget,
269267
});
270-
271-
// ID-3950: https://github.com/authts/oidc-client-ts/issues/2043
272-
// The promise returned from `signinPopup` no longer rejects when the popup is closed.
273-
// We can prevent this from impacting consumers by obtaining a reference to the popup and rejecting the promise
274-
// that is returned by this method if the popup is closed by the user.
275-
276-
// Attempt to get a reference to the popup window
277-
const popupRef = window.open('', popupWindowTarget);
278-
if (popupRef) {
279-
// Create a promise that rejects when popup is closed
280-
const popupClosedPromise = new Promise<never>((_, reject) => {
281-
const timer = setInterval(() => {
282-
if (popupRef.closed) {
283-
clearInterval(timer);
284-
reject(new Error('Popup closed by user'));
285-
}
286-
}, LOGIN_POPUP_CLOSED_POLLING_DURATION);
287-
288-
// Clean up timer when the user promise resolves/rejects
289-
userPromise.finally(() => {
290-
clearInterval(timer);
291-
popupRef.close();
292-
});
293-
});
294-
295-
// Race between user authentication and popup being closed
296-
return Promise.race([userPromise, popupClosedPromise]);
297-
}
298-
299-
return userPromise;
300268
};
301269

302270
// This promise attempts to open the signin popup, and displays the blocked popup overlay if necessary.
@@ -360,33 +328,8 @@ export default class AuthManager {
360328
return user || this.login();
361329
}
362330

363-
private static shouldUseSigninPopupCallback(): boolean {
364-
// ID-3950: https://github.com/authts/oidc-client-ts/issues/2043
365-
// Detect when the login was initiated via a popup
366-
try {
367-
const urlParams = new URLSearchParams(window.location.search);
368-
const stateParam = urlParams.get('state');
369-
const localStorageKey = `oidc.${stateParam}`;
370-
371-
const localStorageValue = localStorage.getItem(localStorageKey);
372-
const loginState = JSON.parse(localStorageValue || '{}');
373-
374-
return loginState?.request_type === 'si:p';
375-
} catch (err) {
376-
return false;
377-
}
378-
}
379-
380331
public async loginCallback(): Promise<undefined | User> {
381332
return withPassportError<undefined | User>(async () => {
382-
// ID-3950: https://github.com/authts/oidc-client-ts/issues/2043
383-
// When using `signinPopup` to initiate a login, call the `signinPopupCallback` method and
384-
// set the `keepOpen` flag to `true`, as the `login` method is now responsible for closing the popup.
385-
// See the comment in the `login` method for more details.
386-
if (AuthManager.shouldUseSigninPopupCallback()) {
387-
await this.userManager.signinPopupCallback(undefined, true);
388-
return undefined;
389-
}
390333
const oidcUser = await this.userManager.signinCallback();
391334
if (!oidcUser) {
392335
return undefined;

packages/x-provider/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"enc-utils": "^3.0.0",
1616
"ethers": "^6.13.4",
1717
"magic-sdk": "^29.0.5",
18-
"oidc-client-ts": "3.3.0"
18+
"oidc-client-ts": "3.4.1"
1919
},
2020
"devDependencies": {
2121
"@swc/core": "^1.3.36",

pnpm-lock.yaml

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)