From 7fa561560de823baa2e3efa0e36354f990b6cbef Mon Sep 17 00:00:00 2001 From: Martin Trajanovski Date: Wed, 18 Oct 2023 13:51:29 +0200 Subject: [PATCH] move flattenObject into util functions file --- src/auth/auth.service.ts | 21 ++------------------- src/common/utils.ts | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts index b1af0b667..c109dad06 100644 --- a/src/auth/auth.service.ts +++ b/src/auth/auth.service.ts @@ -6,7 +6,7 @@ import { User } from "src/users/schemas/user.schema"; import { UsersService } from "../users/users.service"; import { Request } from "express"; import { OidcConfig } from "src/config/configuration"; -import { parseBoolean } from "src/common/utils"; +import { flattenObject, parseBoolean } from "src/common/utils"; import { Issuer } from "openid-client"; @Injectable() @@ -75,23 +75,6 @@ export class AuthService { } } - // eslint-disable-next-line @typescript-eslint/no-explicit-any - flattenObject = (obj: any) => { - const result: Record = {}; - - for (const i in obj) { - if (typeof obj[i] === "object" && !Array.isArray(obj[i])) { - const temp = this.flattenObject(obj[i]); - for (const j in temp) { - result[i + "." + j] = temp[j]; - } - } else { - result[i] = obj[i]; - } - } - return result; - }; - async additionalLogoutTasks(req: Request, logoutURL: string) { const user = req.user as Omit; if (user?.authStrategy === "oidc") { @@ -111,7 +94,7 @@ export class AuthService { `${oidcConfig?.issuer}/.well-known/openid-configuration`, ); // Flatten the object in case the end_session url is nested. - const flattenTrustIssuer = this.flattenObject(trustIssuer); + const flattenTrustIssuer = flattenObject(trustIssuer); // Note search for "end_session" key into the flatten object const endSessionEndpointKey = Object.keys(flattenTrustIssuer).find( diff --git a/src/common/utils.ts b/src/common/utils.ts index 314012af6..b018a7e4f 100644 --- a/src/common/utils.ts +++ b/src/common/utils.ts @@ -176,6 +176,22 @@ export const extractMetadataKeys = ( return Array.from(keys); }; +export const flattenObject = (obj: T) => { + const result: Record = {}; + + for (const i in obj) { + if (typeof obj[i] === "object" && !Array.isArray(obj[i])) { + const temp = flattenObject(obj[i]); + for (const j in temp) { + result[i + "." + j] = temp[j]; + } + } else { + result[i] = obj[i]; + } + } + return result; +}; + export const handleAxiosRequestError = ( err: unknown, context?: string,