Updated secrets held in env vars.

This commit is contained in:
Tom Butcher 2025-12-13 23:54:25 +00:00
parent 787e8f6a9c
commit 85e2ad8d6f
5 changed files with 21 additions and 9 deletions

1
.env.example Normal file
View File

@ -0,0 +1 @@
KEYCLOAK_CLIENT_SECRET='SECRET'

2
.gitignore vendored
View File

@ -130,3 +130,5 @@ dist
.pnp.*
*.DS_STORE
*.env

View File

@ -50,8 +50,7 @@ The application uses `config.json` for configuration. Update the following secti
"keycloak": {
"url": "https://your-keycloak-server",
"realm": "your-realm",
"clientId": "your-client-id",
"clientSecret": "your-client-secret"
"clientId": "your-client-id"
}
}
}
@ -71,7 +70,6 @@ npm run dev
npm start
```
## API Endpoints
The service exposes WebSocket endpoints for:

View File

@ -9,8 +9,7 @@
"keycloak": {
"url": "https://auth.tombutcher.work",
"realm": "master",
"clientId": "farmcontrol-client",
"clientSecret": "GPyh59xctRX83yfKWb83ShK6VEwHIvLF"
"clientId": "farmcontrol-client"
},
"requiredRoles": []
},
@ -32,14 +31,13 @@
"keycloak": {
"url": "https://auth.tombutcher.work",
"realm": "master",
"clientId": "farmcontrol-client",
"clientSecret": "GPyh59xctRX83yfKWb83ShK6VEwHIvLF"
"clientId": "farmcontrol-client"
},
"requiredRoles": []
},
"database": {
"mongo": {
"url": "mongodb://farmcontrol.tombutcher.local:27017/farmcontrol"
"url": "mongodb://localhost:27017/farmcontrol"
}
}
}

View File

@ -27,7 +27,20 @@ export function loadConfig() {
);
}
return config[NODE_ENV];
const envConfig = config[NODE_ENV];
// Override keycloak client secret with environment variable if available
if (process.env.KEYCLOAK_CLIENT_SECRET) {
if (!envConfig.auth) {
envConfig.auth = {};
}
if (!envConfig.auth.keycloak) {
envConfig.auth.keycloak = {};
}
envConfig.auth.keycloak.clientSecret = process.env.KEYCLOAK_CLIENT_SECRET;
}
return envConfig;
} catch (err) {
console.error('Error loading config:', err);
throw err;