From 804422a6f00862c2e0ad08b053d4e7c00acabb0f Mon Sep 17 00:00:00 2001 From: merlinz01 Date: Wed, 28 Aug 2024 14:22:39 -0400 Subject: [PATCH] Add JWT authentication type to MultipleAuthentication Signed-off-by: merlinz01 --- public/apps/login/login-page.tsx | 24 +++++++----------------- server/auth/types/multiple/multi_auth.ts | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/public/apps/login/login-page.tsx b/public/apps/login/login-page.tsx index 4591c032..0c3687c1 100644 --- a/public/apps/login/login-page.tsx +++ b/public/apps/login/login-page.tsx @@ -168,22 +168,18 @@ export function LoginPage(props: LoginPageDeps) { const formOptions = (options: string | string[]) => { let formBody = []; const formBodyOp = []; - let authOpts = []; + let authOpts: string[] = []; if (typeof options === 'string') { - if (options === '') { - authOpts.push(AuthType.BASIC); - } else { + if (options !== '') { authOpts.push(options.toLowerCase()); } - } else { - if (options && options.length === 1 && options[0] === '') { - authOpts.push(AuthType.BASIC); - } else { - authOpts = [...options]; - } + } else if (!(options && options.length === 1 && options[0] === '')) { + authOpts = [...options]; } + authOpts = authOpts.filter((auth) => auth !== AuthType.PROXY && auth !== AuthType.JWT); + for (let i = 0; i < authOpts.length; i++) { switch (authOpts[i].toLowerCase()) { case AuthType.BASIC: { @@ -237,10 +233,7 @@ export function LoginPage(props: LoginPageDeps) { ); } - if ( - authOpts.length > 1 && - !(authOpts.includes(AuthType.PROXY) && authOpts.length === 2) - ) { + if (authOpts.length > 1) { formBody.push(); formBody.push(); formBody.push(); @@ -261,9 +254,6 @@ export function LoginPage(props: LoginPageDeps) { formBodyOp.push(renderLoginButton(AuthType.SAML, samlAuthLoginUrl, samlConfig)); break; } - case AuthType.PROXY: { - break; - } default: { setloginFailed(true); setloginError( diff --git a/server/auth/types/multiple/multi_auth.ts b/server/auth/types/multiple/multi_auth.ts index 4b4f6483..886008d6 100644 --- a/server/auth/types/multiple/multi_auth.ts +++ b/server/auth/types/multiple/multi_auth.ts @@ -34,6 +34,7 @@ import { OpenIdAuthentication, ProxyAuthentication, SamlAuthentication, + JwtAuthentication, } from '../../types'; export class MultipleAuthentication extends AuthenticationType { @@ -111,6 +112,19 @@ export class MultipleAuthentication extends AuthenticationType { this.authHandlers.set(AuthType.PROXY, ProxyAuth); break; } + case AuthType.JWT: { + const JwtAuth = new JwtAuthentication( + this.config, + this.sessionStorageFactory, + this.router, + this.esClient, + this.coreSetup, + this.logger + ); + await JwtAuth.init(); + this.authHandlers.set(AuthType.JWT, JwtAuth); + break; + } default: { throw new Error(`Unsupported authentication type: ${this.authTypes[i]}`); }