diff --git a/README.md b/README.md index 64711aac..0e3a1afa 100644 --- a/README.md +++ b/README.md @@ -6,20 +6,21 @@ ### Requisites -- You need NodeJS 20. Use [nvm](https://github.com/nvm-sh/nvm?tab=readme-ov-file#install--update-script) to install NodeJS +- NodeJS 20. Use [nvm](https://github.com/nvm-sh/nvm?tab=readme-ov-file#install--update-script) to install NodeJS ```shell nvm install 20 nvm use 20 ``` -Verify your NodeJS and NPM version with: +- Backend. Clone [trustify](https://github.com/trustification/trustify) and there execute: ```shell -node --version -npm --version +cargo run --bin trustd ``` +It will start the backend in http://localhost:8080 + ### Install dependencies ```shell @@ -43,15 +44,15 @@ Open browser at ## Environment variables -| ENV VAR | Description | Default value | -| ---------------------- | ----------------------------- | ------------------------------------ | -| TRUSTIFICATION_API_URL | Set Trustification API URL | `http://localhost:8080` | -| AUTH_REQUIRED | Enable/Disable authentication | false | -| OIDC_CLIENT_ID | Set Oidc Client | frontend | -| OIDC_SERVER_URL | Set Oidc Server URL | `http://localhost:8090/realms/chicken` | -| OIDC_SCOPE | Set Oidc Scope | openid | -| ANALYTICS_ENABLED | Enable/Disable analytics | false | -| ANALYTICS_WRITE_KEY | Set Segment Write key | null | +| ENV VAR | Description | Default value | +| ------------------- | ----------------------------- | --------------------------------------- | +| TRUSTIFY_API_URL | Set Trustification API URL | `http://localhost:8080` | +| AUTH_REQUIRED | Enable/Disable authentication | true | +| OIDC_CLIENT_ID | Set Oidc Client | frontend | +| OIDC_SERVER_URL | Set Oidc Server URL | `http://localhost:8090/realms/trustify` | +| OIDC_SCOPE | Set Oidc Scope | openid | +| ANALYTICS_ENABLED | Enable/Disable analytics | false | +| ANALYTICS_WRITE_KEY | Set Segment Write key | null | ## Mock data diff --git a/client/src/app/axios-config/apiInit.ts b/client/src/app/axios-config/apiInit.ts index 8c16f7da..6a4287b5 100644 --- a/client/src/app/axios-config/apiInit.ts +++ b/client/src/app/axios-config/apiInit.ts @@ -1,10 +1,11 @@ -import ENV from "@app/env"; import axios from "axios"; import { User } from "oidc-client-ts"; +import { OIDC_CLIENT_ID, OIDC_SERVER_URL } from "@app/oidc"; + function getUser() { const oidcStorage = sessionStorage.getItem( - `oidc.user:${ENV.OIDC_SERVER_URL}:${ENV.OIDC_CLIENT_ID}` + `oidc.user:${OIDC_SERVER_URL}:${OIDC_CLIENT_ID}` ); if (!oidcStorage) { return null; diff --git a/client/src/app/oidc.ts b/client/src/app/oidc.ts index 93b9a225..30895374 100644 --- a/client/src/app/oidc.ts +++ b/client/src/app/oidc.ts @@ -1,9 +1,13 @@ import { OidcClientSettings } from "oidc-client-ts"; import { ENV } from "./env"; +export const OIDC_SERVER_URL = + ENV.OIDC_SERVER_URL || "http://localhost:8090/realms/trustify"; +export const OIDC_CLIENT_ID = ENV.OIDC_CLIENT_ID || "frontend"; + export const oidcClientSettings: OidcClientSettings = { - authority: ENV.OIDC_SERVER_URL || "http://localhost:8090/realms/chicken", - client_id: ENV.OIDC_CLIENT_ID || "frontend", + authority: OIDC_SERVER_URL, + client_id: OIDC_CLIENT_ID, redirect_uri: window.location.href, post_logout_redirect_uri: window.location.href.split("?")[0], response_type: "code", diff --git a/common/src/environment.ts b/common/src/environment.ts index d3d9fcb2..cee30a1b 100644 --- a/common/src/environment.ts +++ b/common/src/environment.ts @@ -20,7 +20,7 @@ export type TrustificationEnvType = { AUTH_REQUIRED: "true" | "false"; /** SSO / Oidc client id */ - OIDC_CLIENT_ID: string; + OIDC_CLIENT_ID?: string; /** SSO / Oidc scope */ OIDC_SCOPE?: string; @@ -35,7 +35,7 @@ export type TrustificationEnvType = { OIDC_SERVER_URL?: string; /** Target URL for the UI server's `/api` proxy */ - TRUSTIFICATION_API_URL?: string; + TRUSTIFY_API_URL?: string; /** Location of branding files (relative paths computed from the project source root) */ BRANDING?: string; @@ -51,7 +51,7 @@ export type TrustificationEnvType = { * Keys in `TrustificationEnv` that are only used on the server and therefore do not * need to be sent to the client. */ -export const SERVER_ENV_KEYS = ["PORT", "TRUSTIFICATION_API_URL", "BRANDING"]; +export const SERVER_ENV_KEYS = ["PORT", "TRUSTIFY_API_URL", "BRANDING"]; /** * Create a `TrustificationEnv` from a partial `TrustificationEnv` with a set of default values. @@ -63,12 +63,12 @@ export const buildTrustificationEnv = ({ MOCK = "off", OIDC_SERVER_URL, - AUTH_REQUIRED = "false", - OIDC_CLIENT_ID = "frontend", + AUTH_REQUIRED = "true", + OIDC_CLIENT_ID, OIDC_SCOPE, UI_INGRESS_PROXY_BODY_SIZE = "500m", - TRUSTIFICATION_API_URL, + TRUSTIFY_API_URL, BRANDING, ANALYTICS_ENABLED = "false", @@ -85,7 +85,7 @@ export const buildTrustificationEnv = ({ OIDC_SCOPE, UI_INGRESS_PROXY_BODY_SIZE, - TRUSTIFICATION_API_URL, + TRUSTIFY_API_URL, BRANDING, ANALYTICS_ENABLED, diff --git a/common/src/proxies.ts b/common/src/proxies.ts index b85c9882..9493ee1e 100644 --- a/common/src/proxies.ts +++ b/common/src/proxies.ts @@ -3,8 +3,7 @@ import { TRUSTIFICATION_ENV } from "./environment.js"; export const proxyMap: Record = { "/api": { - target: - TRUSTIFICATION_ENV.TRUSTIFICATION_API_URL || "http://localhost:8080", + target: TRUSTIFICATION_ENV.TRUSTIFY_API_URL || "http://localhost:8080", logLevel: process.env.DEBUG ? "debug" : "info", changeOrigin: true, diff --git a/entrypoint.sh b/entrypoint.sh index aa785ee6..b4d9f0b8 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -2,8 +2,8 @@ set -e -if [[ -z "$TRUSTIFICATION_API_URL" ]]; then - echo "You must provide TRUSTIFICATION_API_URL environment variable" 1>&2 +if [[ -z "$TRUSTIFY_API_URL" ]]; then + echo "You must provide TRUSTIFY_API_URL environment variable" 1>&2 exit 1 fi