Skip to content

Commit bb95927

Browse files
authored
fix: cross_origin_auth is deprecated and migrated to cross_origin_authentication (#1223)
* fix: added warning for legacy cross_origin_auth and added sanitizeDeprecatedClientFields for handling deprecated field and new field * test: add migration tests for deprecated cross_origin_auth to cross_origin_authentication * fix: rename variable for clarity in sanitizeClientFields function * fix: update client sanitization to handle deprecated cross_origin_auth field * fix: refactor client field sanitization to improve clarity and handle deprecated cross_origin_auth field * fix: specify type for fields in sanitizeClientFields function * fix: rename variable for clarity in sanitizeClientFields function and update handling of deprecated cross_origin_auth field * fix: migrate deprecated cross_origin_auth to cross_origin_authentication in client export * fix: ensure newline at end of file in clients.tests.js * fix: refactor cross_origin_auth sanitization into a dedicated method * fix: improve client field sanitization and handle deprecated cross_origin_auth field * Refactor code structure for improved readability and maintainability * fix: correct spelling of 'sanitized' in client field sanitization methods * fix: update deprecation warning for 'cross_origin_auth' parameter
1 parent a5e623b commit bb95927

8 files changed

Lines changed: 16428 additions & 9595 deletions

src/tools/auth0/handlers/clients.ts

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ import {
33
ClientExpressConfiguration,
44
ClientOrganizationRequireBehaviorEnum,
55
} from 'auth0';
6+
import { has, omit } from 'lodash';
67
import { Assets, Auth0APIClient } from '../../../types';
78
import { paginate } from '../client';
89
import DefaultAPIHandler from './default';
910
import { getConnectionProfile } from './connectionProfiles';
1011
import { getUserAttributeProfiles } from './userAttributeProfiles';
12+
import log from '../../../logger';
1113

1214
const multiResourceRefreshTokenPoliciesSchema = {
1315
type: ['array', 'null'],
@@ -276,6 +278,8 @@ export type Client = {
276278
app_type?: string;
277279
is_first_party?: boolean;
278280
resource_server_identifier?: string;
281+
cross_origin_authentication?: boolean;
282+
cross_origin_auth?: boolean;
279283
custom_login_page?: string;
280284
custom_login_page_on?: boolean;
281285
express_configuration?: ClientExpressConfiguration;
@@ -344,9 +348,10 @@ export default class ClientHandler extends DefaultAPIHandler {
344348
);
345349

346350
// Sanitize client fields
347-
const sanitizeClientFields = (list: Client[]): Client[] =>
348-
list.map((item) => {
349-
// For resourceServers app type `resource_server`, don't include `oidc_backchannel_logout`, `oidc_logout`, `refresh_token`
351+
const sanitizeClientFields = (list: Client[]): Client[] => {
352+
const sanitizedClients = this.sanitizeCrossOriginAuth(list);
353+
354+
return sanitizedClients.map((item: Client) => {
350355
if (item.app_type === 'resource_server') {
351356
if ('oidc_backchannel_logout' in item) {
352357
delete item.oidc_backchannel_logout;
@@ -360,6 +365,7 @@ export default class ClientHandler extends DefaultAPIHandler {
360365
}
361366
return item;
362367
});
368+
};
363369

364370
const changes = {
365371
del: sanitizeClientFields(filterClients(del as Client[])),
@@ -373,6 +379,44 @@ export default class ClientHandler extends DefaultAPIHandler {
373379
});
374380
}
375381

382+
/**
383+
* @description
384+
* Sanitize the deprecated field `cross_origin_auth` to `cross_origin_authentication`
385+
*
386+
* @param {Client[]} clients - The client array to sanitize.
387+
* @returns {Client[]} The sanitized array of clients.
388+
*/
389+
private sanitizeCrossOriginAuth(clients: Client[]): Client[] {
390+
const deprecatedClients: string[] = [];
391+
392+
const updatedClients = clients.map((client) => {
393+
let updated: Client = { ...client };
394+
395+
if (has(updated, 'cross_origin_auth')) {
396+
deprecatedClients.push(client.name);
397+
398+
if (!has(updated, 'cross_origin_authentication')) {
399+
updated.cross_origin_authentication = updated.cross_origin_auth;
400+
}
401+
402+
updated = omit(updated, 'cross_origin_auth') as Client;
403+
}
404+
405+
return updated;
406+
});
407+
408+
if (deprecatedClients.length > 0) {
409+
log.warn(
410+
"The 'cross_origin_auth' parameter is deprecated in clients and scheduled for removal in future releases.\n" +
411+
`Use 'cross_origin_authentication' going forward. Clients using the deprecated setting: [${deprecatedClients.join(
412+
', '
413+
)}]`
414+
);
415+
}
416+
417+
return updatedClients;
418+
}
419+
376420
async getType() {
377421
if (this.existing) return this.existing;
378422

@@ -387,7 +431,9 @@ export default class ClientHandler extends DefaultAPIHandler {
387431
...(excludeThirdPartyClients && { is_first_party: true }),
388432
});
389433

390-
this.existing = clients;
434+
const sanitizedClients = this.sanitizeCrossOriginAuth(clients);
435+
436+
this.existing = sanitizedClients;
391437
return this.existing;
392438
}
393439

0 commit comments

Comments
 (0)