Skip to content

Commit a3812f4

Browse files
chore: replace deprecated exchangeToken with loginWithCustomTokenExchange in web adapter (#1496)
1 parent 9027c92 commit a3812f4

2 files changed

Lines changed: 14 additions & 10 deletions

File tree

src/platforms/web/adapters/WebAuth0Client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ export class WebAuth0Client implements IAuth0Client {
230230
// Apply default scope if not provided for consistency with native platforms
231231
const finalScope = scope ?? 'openid profile email';
232232

233-
const response = await this.client.exchangeToken({
233+
const response = await this.client.loginWithCustomTokenExchange({
234234
subject_token: subjectToken,
235235
subject_token_type: subjectTokenType,
236236
audience,

src/platforms/web/adapters/__tests__/WebAuth0Client.spec.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -347,12 +347,12 @@ describe('WebAuth0Client', () => {
347347
};
348348

349349
beforeEach(() => {
350-
mockSpaClient.exchangeToken = jest
350+
mockSpaClient.loginWithCustomTokenExchange = jest
351351
.fn()
352352
.mockResolvedValue(mockExchangeResponse);
353353
});
354354

355-
it('should call exchangeToken on SPA client with all parameters', async () => {
355+
it('should call loginWithCustomTokenExchange on SPA client with all parameters', async () => {
356356
const parameters = {
357357
subjectToken: 'external-token',
358358
subjectTokenType: 'urn:acme:legacy-token',
@@ -363,7 +363,7 @@ describe('WebAuth0Client', () => {
363363

364364
await client.customTokenExchange(parameters);
365365

366-
expect(mockSpaClient.exchangeToken).toHaveBeenCalledWith({
366+
expect(mockSpaClient.loginWithCustomTokenExchange).toHaveBeenCalledWith({
367367
subject_token: 'external-token',
368368
subject_token_type: 'urn:acme:legacy-token',
369369
audience: 'https://api.example.com',
@@ -372,15 +372,15 @@ describe('WebAuth0Client', () => {
372372
});
373373
});
374374

375-
it('should call exchangeToken with only required parameters', async () => {
375+
it('should call loginWithCustomTokenExchange with only required parameters', async () => {
376376
const parameters = {
377377
subjectToken: 'external-token',
378378
subjectTokenType: 'urn:acme:legacy-token',
379379
};
380380

381381
await client.customTokenExchange(parameters);
382382

383-
expect(mockSpaClient.exchangeToken).toHaveBeenCalledWith({
383+
expect(mockSpaClient.loginWithCustomTokenExchange).toHaveBeenCalledWith({
384384
subject_token: 'external-token',
385385
subject_token_type: 'urn:acme:legacy-token',
386386
audience: undefined,
@@ -420,7 +420,7 @@ describe('WebAuth0Client', () => {
420420
});
421421

422422
it('should use client tokenType as fallback when response token_type is missing', async () => {
423-
mockSpaClient.exchangeToken.mockResolvedValueOnce({
423+
mockSpaClient.loginWithCustomTokenExchange.mockResolvedValueOnce({
424424
...mockExchangeResponse,
425425
token_type: undefined,
426426
});
@@ -434,13 +434,15 @@ describe('WebAuth0Client', () => {
434434
expect(result.tokenType).toBe('DPoP');
435435
});
436436

437-
it('should propagate errors from exchangeToken as AuthenticationException', async () => {
437+
it('should propagate errors from loginWithCustomTokenExchange as AuthenticationException', async () => {
438438
const exchangeError = {
439439
error: 'invalid_grant',
440440
error_description: 'Token exchange failed',
441441
message: 'Token exchange failed',
442442
};
443-
mockSpaClient.exchangeToken.mockRejectedValueOnce(exchangeError);
443+
mockSpaClient.loginWithCustomTokenExchange.mockRejectedValueOnce(
444+
exchangeError
445+
);
444446

445447
await expect(
446448
client.customTokenExchange({
@@ -462,7 +464,9 @@ describe('WebAuth0Client', () => {
462464

463465
it('should wrap generic errors in AuthenticationException', async () => {
464466
const genericError = new Error('Network error');
465-
mockSpaClient.exchangeToken.mockRejectedValueOnce(genericError);
467+
mockSpaClient.loginWithCustomTokenExchange.mockRejectedValueOnce(
468+
genericError
469+
);
466470

467471
await expect(
468472
client.customTokenExchange({

0 commit comments

Comments
 (0)