From 3bd9997457df51707e4e793814a7040f9e7bc1d0 Mon Sep 17 00:00:00 2001 From: Nicholas Bucher Date: Wed, 23 Oct 2024 15:03:14 -0400 Subject: [PATCH 1/2] added options to configure the app details page sections. Signed-off-by: Nicholas Bucher --- Dockerfile | 4 +++- Makefile | 8 +++++++ README.md | 1 + .../v0.0.36/options-for-app-auth-methods.yaml | 6 ++++++ .../Apps/Details/AppDetailsPageContent.tsx | 14 +++++++++++-- projects/ui/src/user_variables.tmplr.ts | 21 +++++++++++++++++++ 6 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 changelog/v0.0.36/options-for-app-auth-methods.yaml diff --git a/Dockerfile b/Dockerfile index 67a74d08..16107832 100644 --- a/Dockerfile +++ b/Dockerfile @@ -49,7 +49,8 @@ ENV VITE_PORTAL_SERVER_URL=$VITE_PORTAL_SERVER_URL \ VITE_CUSTOM_PAGES=$VITE_CUSTOM_PAGES \ VITE_SWAGGER_PREFILL_API_KEY=$VITE_SWAGGER_PREFILL_API_KEY \ VITE_SWAGGER_PREFILL_OAUTH=$VITE_SWAGGER_PREFILL_OAUTH \ - VITE_SWAGGER_PREFILL_BASIC=$VITE_SWAGGER_PREFILL_BASIC + VITE_SWAGGER_PREFILL_BASIC=$VITE_SWAGGER_PREFILL_BASIC \ + VITE_DEFAULT_APP_AUTH_METHOD=$VITE_DEFAULT_APP_AUTH_METHOD # Copy the server files, (this includes the UI build). WORKDIR /app @@ -78,4 +79,5 @@ ENTRYPOINT VITE_PORTAL_SERVER_URL=$VITE_PORTAL_SERVER_URL \ VITE_SWAGGER_PREFILL_API_KEY=$VITE_SWAGGER_PREFILL_API_KEY \ VITE_SWAGGER_PREFILL_OAUTH=$VITE_SWAGGER_PREFILL_OAUTH \ VITE_SWAGGER_PREFILL_BASIC=$VITE_SWAGGER_PREFILL_BASIC \ + VITE_DEFAULT_APP_AUTH_METHOD=$VITE_DEFAULT_APP_AUTH_METHOD \ node ./bin/www diff --git a/Makefile b/Makefile index d42bb2ae..6ea7a615 100644 --- a/Makefile +++ b/Makefile @@ -132,6 +132,14 @@ ifneq ($(VITE_SWAGGER_PREFILL_BASIC),) else ifneq ($(SWAGGER_PREFILL_BASIC),) UI_ARGS += VITE_SWAGGER_PREFILL_BASIC=$(SWAGGER_PREFILL_BASIC) endif +# +# DEFAULT_APP_AUTH_METHOD +ifneq ($(VITE_DEFAULT_APP_AUTH_METHOD),) + UI_ARGS += VITE_DEFAULT_APP_AUTH_METHOD=$(VITE_DEFAULT_APP_AUTH_METHOD) +else ifneq ($(DEFAULT_APP_AUTH_METHOD),) + UI_ARGS += VITE_DEFAULT_APP_AUTH_METHOD=$(DEFAULT_APP_AUTH_METHOD) +endif + diff --git a/README.md b/README.md index 0e437ecd..9af5009a 100644 --- a/README.md +++ b/README.md @@ -151,6 +151,7 @@ You can add these environment variables to a `.env.local` file in the `projects/ VITE_SWAGGER_PREFILL_OAUTH='{"clientId": "your-client-id","clientSecret": "your-client-secret-if-required","realm": "your-realms","appName": "your-app-name","scopeSeparator": " ","scopes": "openid profile","additionalQueryStringParams": {"test": "hello"},"useBasicAuthenticationWithAccessCodeGrant": true,"usePkceWithAuthorizationCodeGrant": true}' ``` - `VITE_SWAGGER_PREFILL_BASIC` - Prefills the Swagger UI authorization configuration for a Basic authorization scheme. This can be set using the following format: `'["authDefinitionKey", "username", "password"]'`. +- `VITE_DEFAULT_APP_AUTH_METHOD` - This controls whether the OAuth and/or API Key sections are shown on the App details page. Can be set to `"OAUTH"`, `"API_KEY"`, or `"ALL"`. Defaults to `"ALL"`. #### Environment Variables for PKCE Authorization Flow diff --git a/changelog/v0.0.36/options-for-app-auth-methods.yaml b/changelog/v0.0.36/options-for-app-auth-methods.yaml new file mode 100644 index 00000000..4450ff69 --- /dev/null +++ b/changelog/v0.0.36/options-for-app-auth-methods.yaml @@ -0,0 +1,6 @@ +changelog: + - type: FIX + issueLink: https://github.com/solo-io/solo-projects/issues/7059 + description: >- + Adds an option to configure the UI to show the API Key, OAuth, or both + authorization sections on the App details page. diff --git a/projects/ui/src/Components/Apps/Details/AppDetailsPageContent.tsx b/projects/ui/src/Components/Apps/Details/AppDetailsPageContent.tsx index d440409c..a08f6c17 100644 --- a/projects/ui/src/Components/Apps/Details/AppDetailsPageContent.tsx +++ b/projects/ui/src/Components/Apps/Details/AppDetailsPageContent.tsx @@ -9,6 +9,10 @@ import { } from "../../../Apis/gg_hooks"; import { Icon } from "../../../Assets/Icons"; import { UtilityStyles } from "../../../Styles/shared/Utility.style"; +import { + AppAuthMethod, + defaultAppAuthMethod, +} from "../../../user_variables.tmplr"; import { getTeamDetailsLink } from "../../../Utility/link-builders"; import { BannerHeading } from "../../Common/Banner/BannerHeading"; import { BannerHeadingTitle } from "../../Common/Banner/BannerHeadingTitle"; @@ -77,11 +81,17 @@ export const AppDetailsPageContent = ({ app }: { app: App }) => { /> - + {(defaultAppAuthMethod === AppAuthMethod[AppAuthMethod.ALL] || + defaultAppAuthMethod === AppAuthMethod[AppAuthMethod.OAUTH]) && ( + + )} - + {(defaultAppAuthMethod === AppAuthMethod[AppAuthMethod.ALL] || + defaultAppAuthMethod === AppAuthMethod[AppAuthMethod.API_KEY]) && ( + + )} {isLoadingSubscriptions || subscriptions === undefined ? ( diff --git a/projects/ui/src/user_variables.tmplr.ts b/projects/ui/src/user_variables.tmplr.ts index ec3d672c..2e8764a9 100644 --- a/projects/ui/src/user_variables.tmplr.ts +++ b/projects/ui/src/user_variables.tmplr.ts @@ -246,3 +246,24 @@ export const swaggerPrefillBasic = (() => { } : undefined; })(); + +/** + * This is optional. + */ +export enum AppAuthMethod { + ALL, + OAUTH, + API_KEY, +} +export const defaultAppAuthMethod = templateString( + "{{ tmplr.defaultAppAuthMethod }}", + insertedEnvironmentVariables?.VITE_DEFAULT_APP_AUTH_METHOD, + import.meta.env.VITE_DEFAULT_APP_AUTH_METHOD, + "ALL" +).toUpperCase() as keyof typeof AppAuthMethod; +if (AppAuthMethod[defaultAppAuthMethod] === undefined) { + // eslint-disable-next-line no-console + console.error( + 'The value for `VITE_DEFAULT_APP_AUTH_METHOD` must be: "OAUTH", "ALL", or "API_KEY".' + ); +} From 7125f2f5f1f22d6788ad438a764ccf6ea3272268 Mon Sep 17 00:00:00 2001 From: Nicholas Bucher Date: Wed, 23 Oct 2024 15:07:50 -0400 Subject: [PATCH 2/2] DEFAULT_APP_AUTH rename. Signed-off-by: Nicholas Bucher --- Dockerfile | 4 ++-- Makefile | 10 +++++----- README.md | 2 +- projects/ui/src/user_variables.tmplr.ts | 6 +++--- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index 16107832..4af72dfc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -50,7 +50,7 @@ ENV VITE_PORTAL_SERVER_URL=$VITE_PORTAL_SERVER_URL \ VITE_SWAGGER_PREFILL_API_KEY=$VITE_SWAGGER_PREFILL_API_KEY \ VITE_SWAGGER_PREFILL_OAUTH=$VITE_SWAGGER_PREFILL_OAUTH \ VITE_SWAGGER_PREFILL_BASIC=$VITE_SWAGGER_PREFILL_BASIC \ - VITE_DEFAULT_APP_AUTH_METHOD=$VITE_DEFAULT_APP_AUTH_METHOD + VITE_DEFAULT_APP_AUTH=$VITE_DEFAULT_APP_AUTH # Copy the server files, (this includes the UI build). WORKDIR /app @@ -79,5 +79,5 @@ ENTRYPOINT VITE_PORTAL_SERVER_URL=$VITE_PORTAL_SERVER_URL \ VITE_SWAGGER_PREFILL_API_KEY=$VITE_SWAGGER_PREFILL_API_KEY \ VITE_SWAGGER_PREFILL_OAUTH=$VITE_SWAGGER_PREFILL_OAUTH \ VITE_SWAGGER_PREFILL_BASIC=$VITE_SWAGGER_PREFILL_BASIC \ - VITE_DEFAULT_APP_AUTH_METHOD=$VITE_DEFAULT_APP_AUTH_METHOD \ + VITE_DEFAULT_APP_AUTH=$VITE_DEFAULT_APP_AUTH \ node ./bin/www diff --git a/Makefile b/Makefile index 6ea7a615..3e674485 100644 --- a/Makefile +++ b/Makefile @@ -133,11 +133,11 @@ else ifneq ($(SWAGGER_PREFILL_BASIC),) UI_ARGS += VITE_SWAGGER_PREFILL_BASIC=$(SWAGGER_PREFILL_BASIC) endif # -# DEFAULT_APP_AUTH_METHOD -ifneq ($(VITE_DEFAULT_APP_AUTH_METHOD),) - UI_ARGS += VITE_DEFAULT_APP_AUTH_METHOD=$(VITE_DEFAULT_APP_AUTH_METHOD) -else ifneq ($(DEFAULT_APP_AUTH_METHOD),) - UI_ARGS += VITE_DEFAULT_APP_AUTH_METHOD=$(DEFAULT_APP_AUTH_METHOD) +# DEFAULT_APP_AUTH +ifneq ($(VITE_DEFAULT_APP_AUTH),) + UI_ARGS += VITE_DEFAULT_APP_AUTH=$(VITE_DEFAULT_APP_AUTH) +else ifneq ($(DEFAULT_APP_AUTH),) + UI_ARGS += VITE_DEFAULT_APP_AUTH=$(DEFAULT_APP_AUTH) endif diff --git a/README.md b/README.md index 9af5009a..b3cf3a68 100644 --- a/README.md +++ b/README.md @@ -151,7 +151,7 @@ You can add these environment variables to a `.env.local` file in the `projects/ VITE_SWAGGER_PREFILL_OAUTH='{"clientId": "your-client-id","clientSecret": "your-client-secret-if-required","realm": "your-realms","appName": "your-app-name","scopeSeparator": " ","scopes": "openid profile","additionalQueryStringParams": {"test": "hello"},"useBasicAuthenticationWithAccessCodeGrant": true,"usePkceWithAuthorizationCodeGrant": true}' ``` - `VITE_SWAGGER_PREFILL_BASIC` - Prefills the Swagger UI authorization configuration for a Basic authorization scheme. This can be set using the following format: `'["authDefinitionKey", "username", "password"]'`. -- `VITE_DEFAULT_APP_AUTH_METHOD` - This controls whether the OAuth and/or API Key sections are shown on the App details page. Can be set to `"OAUTH"`, `"API_KEY"`, or `"ALL"`. Defaults to `"ALL"`. +- `VITE_DEFAULT_APP_AUTH` - This controls whether the OAuth and/or API Key sections are shown on the App details page. Can be set to `"OAUTH"`, `"API_KEY"`, or `"ALL"`. Defaults to `"ALL"`. #### Environment Variables for PKCE Authorization Flow diff --git a/projects/ui/src/user_variables.tmplr.ts b/projects/ui/src/user_variables.tmplr.ts index 2e8764a9..39d4e9c1 100644 --- a/projects/ui/src/user_variables.tmplr.ts +++ b/projects/ui/src/user_variables.tmplr.ts @@ -257,13 +257,13 @@ export enum AppAuthMethod { } export const defaultAppAuthMethod = templateString( "{{ tmplr.defaultAppAuthMethod }}", - insertedEnvironmentVariables?.VITE_DEFAULT_APP_AUTH_METHOD, - import.meta.env.VITE_DEFAULT_APP_AUTH_METHOD, + insertedEnvironmentVariables?.VITE_DEFAULT_APP_AUTH, + import.meta.env.VITE_DEFAULT_APP_AUTH, "ALL" ).toUpperCase() as keyof typeof AppAuthMethod; if (AppAuthMethod[defaultAppAuthMethod] === undefined) { // eslint-disable-next-line no-console console.error( - 'The value for `VITE_DEFAULT_APP_AUTH_METHOD` must be: "OAUTH", "ALL", or "API_KEY".' + 'The value for `VITE_DEFAULT_APP_AUTH` must be: "OAUTH", "ALL", or "API_KEY".' ); }