From 8a961056005eebced69a3f36be520ac70516c829 Mon Sep 17 00:00:00 2001 From: ivakoleva Date: Thu, 27 Apr 2023 17:00:07 +0300 Subject: [PATCH] frontend: Toggleable auth (#1958) We need a feature flag for skipping OAuth2, so the frontend can operate with a Control Service where security is disabled. It is the default use case when having quickstart-vdk for local demo or dev installation. This is a stacked PR onto auth configurations organized from https://github.com/vmware/versatile-data-kit/pull/1957 Introduced authSkipped flag defaulting to false, due security standards. The top right corner with username and logout dropdown are rendered in case auth is enabled. Testing done: verified both cases locally; added testing --------- Signed-off-by: ivakoleva Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .../projects/ui/src/app/app-config.model.ts | 3 +- .../projects/ui/src/app/app-config.service.ts | 6 ++ .../projects/ui/src/app/app.component.html | 10 +-- .../projects/ui/src/app/app.component.spec.ts | 72 ++++++++++--------- .../gui/projects/ui/src/app/app.component.ts | 35 ++++++--- .../gui/projects/ui/src/app/app.module.ts | 6 +- .../projects/ui/src/app/http.interceptor.ts | 7 +- .../ui/src/assets/data/appConfig.json | 1 + 8 files changed, 85 insertions(+), 55 deletions(-) diff --git a/projects/frontend/data-pipelines/gui/projects/ui/src/app/app-config.model.ts b/projects/frontend/data-pipelines/gui/projects/ui/src/app/app-config.model.ts index ff6db19002..34cb7f9cf3 100644 --- a/projects/frontend/data-pipelines/gui/projects/ui/src/app/app-config.model.ts +++ b/projects/frontend/data-pipelines/gui/projects/ui/src/app/app-config.model.ts @@ -10,13 +10,14 @@ export interface AppConfig { } export interface Auth { + skipAuth?: false; + // Used for producing the AuthConfig.customQueryParams mapping for `orgLink` and `targetUri` consoleCloudUrl?: string; orgLinkRoot?: string; // $window.location.origin is replaced with the corresponding value dynamically upon loading, // see AppConfigService authConfig?: AuthConfig; - resourceServer?: OAuthResourceServerConfig; // Used for token auto-refresh capability, in case a token is about to expire. refreshTokenConfig?: RefreshTokenConfig; diff --git a/projects/frontend/data-pipelines/gui/projects/ui/src/app/app-config.service.ts b/projects/frontend/data-pipelines/gui/projects/ui/src/app/app-config.service.ts index 2f77e12a21..f716b68bf2 100644 --- a/projects/frontend/data-pipelines/gui/projects/ui/src/app/app-config.service.ts +++ b/projects/frontend/data-pipelines/gui/projects/ui/src/app/app-config.service.ts @@ -30,7 +30,12 @@ export class AppConfigService { return this.appConfig; } + getSkipAuth(): boolean { + return this.appConfig.auth.skipAuth; + } + getAuthCodeFlowConfig(): AuthConfig { + if (this.getSkipAuth()) return new AuthConfig(); const replaceWindowLocationOrigin = (str: string): string => { return str?.replace('$window.location.origin', window.location.origin); }; @@ -42,6 +47,7 @@ export class AppConfigService { } getRefreshTokenConfig(): RefreshTokenConfig { + if (this.getSkipAuth()) return null; return this.getConfig()?.auth.refreshTokenConfig; } } diff --git a/projects/frontend/data-pipelines/gui/projects/ui/src/app/app.component.html b/projects/frontend/data-pipelines/gui/projects/ui/src/app/app.component.html index fb31bdd180..21ec3a466c 100644 --- a/projects/frontend/data-pipelines/gui/projects/ui/src/app/app.component.html +++ b/projects/frontend/data-pipelines/gui/projects/ui/src/app/app.component.html @@ -3,8 +3,10 @@ ~ SPDX-License-Identifier: Apache-2.0 --> - - + +
-
+