Skip to content

Commit 0df3096

Browse files
author
Mohammed Abdi
authored
Dynamic auth client_id and keycloak_realm Env Variables (#401)
* dynamic auth client id and keycloak realm Signed-off-by: MohammedAbdi <mohammma@usc.edu> * add env auth variables in prod Signed-off-by: MohammedAbdi <mohammma@usc.edu> * add documentation Signed-off-by: MohammedAbdi <mohammma@usc.edu> --------- Signed-off-by: MohammedAbdi <mohammma@usc.edu>
1 parent b03fee1 commit 0df3096

File tree

6 files changed

+21
-4
lines changed

6 files changed

+21
-4
lines changed

USAGE.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ The frontend is meant to connect to either the Tornjak backend or the Tornjak ma
5757
| `NODE_OPTIONS` | Node options for npm start | `--openssl-legacy-provider` | `--openssl-legacy-provider` | false |
5858
| `REACT_APP_TORNJAK_MANAGER` | Boolean for whether the connected server is a manager | `false` | `true` | false |
5959
| `REACT_APP_AUTH_SERVER_URI` | URI for the Keycloak instance to obtain access tokens | | `http://localhost:8080` | false |
60+
| `REACT_APP_KEYCLOAK_REALM` | Name of Keycloak realm | | 'tornjak' | false |
61+
| `REACT_APP_OIDC_CLIENT_ID` | Auth Client ID | | 'tornjak' | false |
6062
| `PORT_FE` | Port for the frontend to run | `3000` | `3000` | true |
6163
| `PORT_BE` | Port for the backend to run | `10000` | `10000` | true |
6264
| `REACT_APP_SPIRE_HEALTH_CHECK_ENABLE` | Enable SPIRE health check component | `false` | `true` | false |

docs/user-management.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,27 @@ with more details on the general configuration
5959
1. **Configure Tornjak Frontend**
6060
Finally, the Frontend must be deployed and configured to obtain access tokens from this auth server.
6161
This can be done locally with the environment variable
62-
`REACT_APP_AUTH_SERVER_URI`:
62+
`REACT_APP_AUTH_SERVER_URI`. In addition `REACT_APP_KEYCLOAK_REALM` and `REACT_APP_OIDC_CLIENT_ID` must be set as well.
63+
64+
Default values are:
65+
66+
`REACT_APP_KEYCLOAK_REALM` - 'tornjak'
67+
68+
`REACT_APP_OIDC_CLIENT_ID` - 'tornjak'
6369

6470
```
6571
cd tornjak-frontend
6672
REACT_APP_API_SERVER_URI=http://localhost:10000/
73+
REACT_APP_KEYCLOAK_REALM=tornjak
74+
REACT_APP_OIDC_CLIENT_ID=tornjak
6775
REACT_APP_AUTH_SERVER_URI=http://localhost:8080/ npm start
6876
```
6977

7078
Alternatively, we can do the same on the containerized version:
7179

7280
```
73-
docker run -p 3000:3000 -d -e REACT_APP_API_SERVER_URI='http://localhost:10000' -e REACT_APP_AUTH_SERVER_URI='http://localhost:8080' ghcr.io/spiffe/tornjak-frontend:v1.5.0
81+
docker run -p 3000:3000 -d -e REACT_APP_API_SERVER_URI='http://localhost:10000' -e REACT_APP_AUTH_SERVER_URI='http://localhost:8080' -e REACT_APP_KEYCLOAK_REALM='tornjak' -e
82+
REACT_APP_OIDC_CLIENT_ID='tornjak' ghcr.io/spiffe/tornjak-frontend:v1.5.0
7483
`
7584
```
7685

frontend/.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ REACT_APP_API_SERVER_URI=http://localhost:10000/
1111

1212
##### For user management #####
1313
# REACT_APP_AUTH_SERVER_URI=http://localhost:8080/
14+
REACT_APP_KEYCLOAK_REALM="tornjak"
15+
REACT_APP_OIDC_CLIENT_ID="tornjak"
1416

1517

1618
##### To check SPIRE health #####

frontend/.env.prod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ REACT_APP_API_SERVER_URI=http://localhost:10000/
55

66
##### For user management #####
77
# REACT_APP_AUTH_SERVER_URI=http://localhost:8080/
8+
REACT_APP_KEYCLOAK_REALM="tornjak"
9+
REACT_APP_OIDC_CLIENT_ID="tornjak"
810

911

1012
##### To check SPIRE health #####

frontend/src/auth/KeycloakAuth.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import Keycloak from "keycloak-js";
22
import {env} from '../env';
33
const keycloakConfig = {
4-
"realm": "tornjak",
4+
"realm": env.REACT_APP_KEYCLOAK_REALM,
55
"url": env.REACT_APP_AUTH_SERVER_URI,
66
"ssl-required": "external",
7-
"clientId": "Tornjak-React-auth",
7+
"clientId": env.REACT_APP_OIDC_CLIENT_ID,
88
"public-client": true,
99
"verify-token-audience": true,
1010
"use-resource-role-mappings": true,

frontend/src/env.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ declare global {
88
REACT_APP_AUTH_SERVER_URI: string,
99
REACT_APP_API_SERVER_URI: string,
1010
REACT_APP_TORNJAK_MANAGER: string,
11+
REACT_APP_KEYCLOAK_REALM: string,
12+
REACT_APP_OIDC_CLIENT_ID: string,
1113
}
1214
export const env: EnvType = { ...process.env, ...window.env }

0 commit comments

Comments
 (0)