Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/platforms/web/adapters/WebAuth0Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ export class WebAuth0Client implements IAuth0Client {
// Apply default scope if not provided for consistency with native platforms
const finalScope = scope ?? 'openid profile email';

const response = await this.client.exchangeToken({
const response = await this.client.loginWithCustomTokenExchange({
subject_token: subjectToken,
subject_token_type: subjectTokenType,
audience,
Expand Down
22 changes: 13 additions & 9 deletions src/platforms/web/adapters/__tests__/WebAuth0Client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,12 @@ describe('WebAuth0Client', () => {
};

beforeEach(() => {
mockSpaClient.exchangeToken = jest
mockSpaClient.loginWithCustomTokenExchange = jest
.fn()
.mockResolvedValue(mockExchangeResponse);
});

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

await client.customTokenExchange(parameters);

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

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

await client.customTokenExchange(parameters);

expect(mockSpaClient.exchangeToken).toHaveBeenCalledWith({
expect(mockSpaClient.loginWithCustomTokenExchange).toHaveBeenCalledWith({
subject_token: 'external-token',
subject_token_type: 'urn:acme:legacy-token',
audience: undefined,
Expand Down Expand Up @@ -420,7 +420,7 @@ describe('WebAuth0Client', () => {
});

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

it('should propagate errors from exchangeToken as AuthenticationException', async () => {
it('should propagate errors from loginWithCustomTokenExchange as AuthenticationException', async () => {
const exchangeError = {
error: 'invalid_grant',
error_description: 'Token exchange failed',
message: 'Token exchange failed',
};
mockSpaClient.exchangeToken.mockRejectedValueOnce(exchangeError);
mockSpaClient.loginWithCustomTokenExchange.mockRejectedValueOnce(
exchangeError
);

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

it('should wrap generic errors in AuthenticationException', async () => {
const genericError = new Error('Network error');
mockSpaClient.exchangeToken.mockRejectedValueOnce(genericError);
mockSpaClient.loginWithCustomTokenExchange.mockRejectedValueOnce(
genericError
);

await expect(
client.customTokenExchange({
Expand Down
Loading