Removed secrets from config.
This commit is contained in:
parent
80aeb116dc
commit
b24c9e1b3e
12
config.json
12
config.json
@ -9,11 +9,9 @@
|
|||||||
"keycloak": {
|
"keycloak": {
|
||||||
"url": "https://auth.tombutcher.work",
|
"url": "https://auth.tombutcher.work",
|
||||||
"realm": "master",
|
"realm": "master",
|
||||||
"clientId": "farmcontrol-client",
|
"clientId": "farmcontrol-client"
|
||||||
"clientSecret": "GPyh59xctRX83yfKWb83ShK6VEwHIvLF"
|
|
||||||
},
|
},
|
||||||
"requiredRoles": [],
|
"requiredRoles": []
|
||||||
"sessionSecret": "n00Dl3s23!"
|
|
||||||
},
|
},
|
||||||
"app": {
|
"app": {
|
||||||
"urlClient": "http://localhost:3000",
|
"urlClient": "http://localhost:3000",
|
||||||
@ -60,11 +58,9 @@
|
|||||||
"keycloak": {
|
"keycloak": {
|
||||||
"url": "https://auth.tombutcher.work",
|
"url": "https://auth.tombutcher.work",
|
||||||
"realm": "master",
|
"realm": "master",
|
||||||
"clientId": "farmcontrol-client",
|
"clientId": "farmcontrol-client"
|
||||||
"clientSecret": "GPyh59xctRX83yfKWb83ShK6VEwHIvLF"
|
|
||||||
},
|
},
|
||||||
"requiredRoles": [],
|
"requiredRoles": []
|
||||||
"sessionSecret": "n00Dl3s23!"
|
|
||||||
},
|
},
|
||||||
"app": {
|
"app": {
|
||||||
"urlClient": "http://localhost:3000",
|
"urlClient": "http://localhost:3000",
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import Keycloak from 'keycloak-connect';
|
|||||||
import session from 'express-session';
|
import session from 'express-session';
|
||||||
import config, { getEnvironment } from './config.js';
|
import config, { getEnvironment } from './config.js';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import jwt from 'jsonwebtoken';
|
import dotenv from 'dotenv';
|
||||||
import log4js from 'log4js';
|
import log4js from 'log4js';
|
||||||
import NodeCache from 'node-cache';
|
import NodeCache from 'node-cache';
|
||||||
import { userModel } from './database/schemas/management/user.schema.js';
|
import { userModel } from './database/schemas/management/user.schema.js';
|
||||||
@ -12,6 +12,8 @@ import { hostModel } from './database/schemas/management/host.schema.js';
|
|||||||
const logger = log4js.getLogger('Keycloak');
|
const logger = log4js.getLogger('Keycloak');
|
||||||
logger.level = config.server.logLevel || 'info';
|
logger.level = config.server.logLevel || 'info';
|
||||||
|
|
||||||
|
dotenv.config();
|
||||||
|
|
||||||
// Initialize NodeCache with 5-minute TTL
|
// Initialize NodeCache with 5-minute TTL
|
||||||
const userCache = new NodeCache({ stdTTL: 300 }); // 300 seconds = 5 minutes
|
const userCache = new NodeCache({ stdTTL: 300 }); // 300 seconds = 5 minutes
|
||||||
|
|
||||||
@ -65,14 +67,14 @@ const keycloakConfig = {
|
|||||||
'use-resource-role-mappings': true,
|
'use-resource-role-mappings': true,
|
||||||
'verify-token-audience': true,
|
'verify-token-audience': true,
|
||||||
credentials: {
|
credentials: {
|
||||||
secret: config.auth.keycloak.clientSecret,
|
secret: process.env.KEYCLOAK_CLIENT_SECRET,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const memoryStore = new session.MemoryStore();
|
const memoryStore = new session.MemoryStore();
|
||||||
|
|
||||||
var expressSession = session({
|
var expressSession = session({
|
||||||
secret: config.auth.sessionSecret,
|
secret: process.env.SESSION_SECRET || 'n00Dl3s23!',
|
||||||
resave: false,
|
resave: false,
|
||||||
saveUninitialized: true, // Set this to true to ensure session is initialized
|
saveUninitialized: true, // Set this to true to ensure session is initialized
|
||||||
store: memoryStore,
|
store: memoryStore,
|
||||||
@ -98,7 +100,7 @@ const isAuthenticated = async (req, res, next) => {
|
|||||||
new URLSearchParams({
|
new URLSearchParams({
|
||||||
token: token,
|
token: token,
|
||||||
client_id: config.auth.keycloak.clientId,
|
client_id: config.auth.keycloak.clientId,
|
||||||
client_secret: config.auth.keycloak.clientSecret,
|
client_secret: process.env.KEYCLOAK_CLIENT_SECRET,
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
|
|||||||
@ -104,7 +104,7 @@ const fetchAndStoreUser = async (req, token) => {
|
|||||||
userInfoUrl,
|
userInfoUrl,
|
||||||
new URLSearchParams({
|
new URLSearchParams({
|
||||||
client_id: config.auth.keycloak.clientId,
|
client_id: config.auth.keycloak.clientId,
|
||||||
client_secret: config.auth.keycloak.clientSecret,
|
client_secret: process.env.KEYCLOAK_CLIENT_SECRET,
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
@ -161,7 +161,7 @@ export const loginTokenRouteHandler = async (req, res, redirectType = 'web') =>
|
|||||||
new URLSearchParams({
|
new URLSearchParams({
|
||||||
grant_type: 'authorization_code',
|
grant_type: 'authorization_code',
|
||||||
client_id: config.auth.keycloak.clientId,
|
client_id: config.auth.keycloak.clientId,
|
||||||
client_secret: config.auth.keycloak.clientSecret,
|
client_secret: process.env.KEYCLOAK_CLIENT_SECRET,
|
||||||
code: code,
|
code: code,
|
||||||
redirect_uri: callbackUrl,
|
redirect_uri: callbackUrl,
|
||||||
}).toString(),
|
}).toString(),
|
||||||
@ -401,7 +401,7 @@ export const refreshTokenRouteHandler = (req, res) => {
|
|||||||
new URLSearchParams({
|
new URLSearchParams({
|
||||||
grant_type: 'refresh_token',
|
grant_type: 'refresh_token',
|
||||||
client_id: config.auth.keycloak.clientId,
|
client_id: config.auth.keycloak.clientId,
|
||||||
client_secret: config.auth.keycloak.clientSecret,
|
client_secret: process.env.KEYCLOAK_CLIENT_SECRET,
|
||||||
refresh_token: refreshToken,
|
refresh_token: refreshToken,
|
||||||
}).toString(),
|
}).toString(),
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user