Skip to content

Commit

Permalink
remove token type validation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharpandey13 committed Mar 6, 2025
1 parent 54e0425 commit 79d5326
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 52 deletions.
25 changes: 2 additions & 23 deletions __tests__/Auth0Client/exchangeToken.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('Auth0Client', () => {
window.location = oldWindowLocation;
});

describe('getTokenWithPopup()', () => {
describe('exchangeToken()', () => {
const localSetup = async (clientOptions?: Partial<Auth0ClientOptions>) => {
const auth0 = setup(clientOptions);

Expand Down Expand Up @@ -98,7 +98,7 @@ describe('Auth0Client', () => {
return auth0;
};

it('calls `loginWithPopup` with the correct default options', async () => {
it('calls `exchangeToken` with the correct default options', async () => {
const auth0 = await localSetup();
const cteOptions: CustomTokenExchangeOptions = {
subject_token: 'external_token_value',
Expand All @@ -113,26 +113,5 @@ describe('Auth0Client', () => {
expect(result.expires_in).toEqual(3600);
expect(typeof result.scope).toBe('string');
});

it('should throw an error for invalid subject_token_type from reserved namespaces', async () => {
// List of reserved token types that must be rejected.
const invalidTokenTypes = [
'urn:ietf:params:oauth:foo',
'https://auth0.com/token',
'urn:auth0:token'
];

const auth0 = await localSetup();

// Each invalid token type should cause exchangeToken to reject with an Error.
for (const tokenType of invalidTokenTypes) {
const cteOptions: CustomTokenExchangeOptions = {
subject_token: 'external_token_value',
subject_token_type: tokenType,
audience: 'https://api.test.com'
};
await expect(auth0.exchangeToken(cteOptions)).rejects.toThrow(Error);
}
});
});
});
4 changes: 1 addition & 3 deletions src/Auth0Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ import {
OLD_IS_AUTHENTICATED_COOKIE_NAME,
patchOpenUrlWithOnRedirect
} from './Auth0Client.utils';
import { CustomTokenExchangeOptions, validateTokenType } from './TokenExchange';
import { CustomTokenExchangeOptions } from './TokenExchange';

/**
* @ignore
Expand Down Expand Up @@ -1195,8 +1195,6 @@ export class Auth0Client {
async exchangeToken(
options: CustomTokenExchangeOptions
): Promise<TokenEndpointResponse> {
validateTokenType(options.subject_token_type);

return this._requestToken({
grant_type: 'urn:ietf:params:oauth:grant-type:token-exchange',
subject_token: options.subject_token,
Expand Down
26 changes: 0 additions & 26 deletions src/TokenExchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,29 +72,3 @@ export type CustomTokenExchangeOptions = {
*/
[key: string]: unknown;
};

/**
* Enforces namespace ownership requirements for token types
*
* @param tokenType - Proposed subject_token_type value
* @throws {Error} When reserved namespace pattern detected
*
* @privateRemarks
* Implements RFC 8693 Section 4.1 requirements for token type URIs
*
* @see {@link https://www.rfc-editor.org/rfc/rfc8693#section-4.1 | RFC 8693 Section 4.1}
*/
export const validateTokenType = (tokenType: string): void => {
const reservedPatterns = [
/^urn:ietf:params:oauth:/i,
/^https:\/\/auth0\.com\//i,
/^urn:auth0:/i
];

if (reservedPatterns.some(pattern => pattern.test(tokenType))) {
throw new Error(
`Invalid subject_token_type '${tokenType}'. ` +
`Reserved namespaces are prohibited. Use URIs under your organization's control.`
);
}
};

0 comments on commit 79d5326

Please sign in to comment.