Skip to content

Commit

Permalink
Enable Auth by default to be aligned with backend default mode (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosthe19916 authored Jun 6, 2024
1 parent 19bb700 commit cdf508b
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 28 deletions.
27 changes: 14 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -43,15 +44,15 @@ Open browser at <http://localhost:3000>

## 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

Expand Down
5 changes: 3 additions & 2 deletions client/src/app/axios-config/apiInit.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
8 changes: 6 additions & 2 deletions client/src/app/oidc.ts
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
14 changes: 7 additions & 7 deletions common/src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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.
Expand All @@ -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",
Expand All @@ -85,7 +85,7 @@ export const buildTrustificationEnv = ({
OIDC_SCOPE,

UI_INGRESS_PROXY_BODY_SIZE,
TRUSTIFICATION_API_URL,
TRUSTIFY_API_URL,
BRANDING,

ANALYTICS_ENABLED,
Expand Down
3 changes: 1 addition & 2 deletions common/src/proxies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { TRUSTIFICATION_ENV } from "./environment.js";

export const proxyMap: Record<string, Options> = {
"/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,
Expand Down
4 changes: 2 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit cdf508b

Please sign in to comment.