Skip to content

Commit bf39d23

Browse files
committed
fix: refactor cross_origin_auth sanitization into a dedicated method
1 parent fbb8b5d commit bf39d23

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

src/tools/auth0/handlers/clients.ts

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -343,17 +343,7 @@ export default class ClientHandler extends DefaultAPIHandler {
343343
list.map((item: Client) => {
344344
let client: Client = { ...item };
345345

346-
// Sanitize the deprecated field `cross_origin_auth` to `cross_origin_authentication`
347-
if (has(client, 'cross_origin_auth')) {
348-
log.warn(
349-
`Client '${item.name}': 'cross_origin_auth' is deprecated and may not be available in the future versions.\nSee more on: https://community.auth0.com/t/action-required-update-applications-that-use-cross-origin-authentication/132819`
350-
);
351-
352-
if (!has(client, 'cross_origin_authentication')) {
353-
client.cross_origin_authentication = client.cross_origin_auth;
354-
}
355-
client = omit(client, 'cross_origin_auth');
356-
}
346+
client = this.sanitizeCrossOriginAuth(client);
357347

358348
if (client.app_type === 'resource_server') {
359349
if ('oidc_backchannel_logout' in client) {
@@ -381,6 +371,30 @@ export default class ClientHandler extends DefaultAPIHandler {
381371
});
382372
}
383373

374+
/**
375+
* @description
376+
* Sanitize the deprecated field `cross_origin_auth` to `cross_origin_authentication`
377+
*
378+
* @param {Client} client - The client object to sanitize.
379+
* @returns {Client} The sanitized client object.
380+
*/
381+
private sanitizeCrossOriginAuth(client: Client): Client {
382+
let updatedClient: Client = { ...client };
383+
384+
if (has(updatedClient, 'cross_origin_auth')) {
385+
log.warn(
386+
`Client '${client.name}': 'cross_origin_auth' is deprecated and may not be available in the future versions.\nSee more on: https://community.auth0.com/t/action-required-update-applications-that-use-cross-origin-authentication/132819`
387+
);
388+
389+
if (!has(updatedClient, 'cross_origin_authentication')) {
390+
updatedClient.cross_origin_authentication = updatedClient.cross_origin_auth;
391+
}
392+
updatedClient = omit(updatedClient, 'cross_origin_auth') as Client;
393+
}
394+
395+
return updatedClient;
396+
}
397+
384398
async getType() {
385399
if (this.existing) return this.existing;
386400

@@ -390,22 +404,7 @@ export default class ClientHandler extends DefaultAPIHandler {
390404
is_global: false,
391405
});
392406

393-
this.existing = clients.map((item: Client) => {
394-
let client: Client = { ...item };
395-
396-
if (has(client, 'cross_origin_auth')) {
397-
log.warn(
398-
`Client '${item.name}': 'cross_origin_auth' is deprecated and may not be available in the future versions.\nSee more on: https://community.auth0.com/t/action-required-update-applications-that-use-cross-origin-authentication/132819`
399-
);
400-
401-
if (!has(client, 'cross_origin_authentication')) {
402-
client.cross_origin_authentication = client.cross_origin_auth;
403-
}
404-
client = omit(client, 'cross_origin_auth');
405-
}
406-
407-
return client;
408-
});
407+
this.existing = clients.map(this.sanitizeCrossOriginAuth.bind(this));
409408

410409
return this.existing;
411410
}

0 commit comments

Comments
 (0)