Load config.local.php from repo root for server-side secrets

Provides a gitignored override file for credentials like LinkedIn OAuth
keys, avoiding reliance on Apache SetEnv / PHP-FPM env config.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Bashy 2026-05-28 12:40:14 +03:00
parent e1f7fb14fc
commit ac5b82c381
4 changed files with 8 additions and 3 deletions

1
.gitignore vendored
View file

@ -8,6 +8,7 @@ web/BUILD
# Local config overrides (never commit secrets) # Local config overrides (never commit secrets)
config/config.local.php config/config.local.php
config.local.php
.env .env
.env.local .env.local

View file

@ -3,6 +3,10 @@ if (!defined('ROOT')) define('ROOT', dirname(__DIR__));
$config = require ROOT . '/config/config.php'; $config = require ROOT . '/config/config.php';
if (file_exists(ROOT . '/config.local.php')) {
require_once ROOT . '/config.local.php';
}
ini_set('session.cookie_httponly', '1'); ini_set('session.cookie_httponly', '1');
ini_set('session.use_strict_mode', '1'); ini_set('session.use_strict_mode', '1');
session_name($config['session_name']); session_name($config['session_name']);

View file

@ -8,7 +8,7 @@ $stmt = $db->prepare('SELECT * FROM projects WHERE id = ? AND is_active = 1');
$stmt->execute([$pid]); $stmt->execute([$pid]);
if (!$stmt->fetch()) { http_response_code(404); echo json_encode(['error' => 'Project not found']); exit; } if (!$stmt->fetch()) { http_response_code(404); echo json_encode(['error' => 'Project not found']); exit; }
$client_id = getenv('LINKEDIN_CLIENT_ID') ?: ($_SERVER['LINKEDIN_CLIENT_ID'] ?? null); $client_id = defined('LINKEDIN_CLIENT_ID') ? LINKEDIN_CLIENT_ID : (getenv('LINKEDIN_CLIENT_ID') ?: ($_SERVER['LINKEDIN_CLIENT_ID'] ?? null));
if (!$client_id) { echo json_encode(['error' => 'LINKEDIN_CLIENT_ID not set in server environment']); exit; } if (!$client_id) { echo json_encode(['error' => 'LINKEDIN_CLIENT_ID not set in server environment']); exit; }
$state = bin2hex(random_bytes(16)); $state = bin2hex(random_bytes(16));

View file

@ -20,8 +20,8 @@ if (isset($_GET['error'])) {
$code = $_GET['code'] ?? ''; $code = $_GET['code'] ?? '';
if (!$code) { echo 'Missing code. <a href="/">Go back</a>'; exit; } if (!$code) { echo 'Missing code. <a href="/">Go back</a>'; exit; }
$client_id = getenv('LINKEDIN_CLIENT_ID') ?: ($_SERVER['LINKEDIN_CLIENT_ID'] ?? null); $client_id = defined('LINKEDIN_CLIENT_ID') ? LINKEDIN_CLIENT_ID : (getenv('LINKEDIN_CLIENT_ID') ?: ($_SERVER['LINKEDIN_CLIENT_ID'] ?? null));
$client_secret = getenv('LINKEDIN_CLIENT_SECRET') ?: ($_SERVER['LINKEDIN_CLIENT_SECRET'] ?? null); $client_secret = defined('LINKEDIN_CLIENT_SECRET') ? LINKEDIN_CLIENT_SECRET : (getenv('LINKEDIN_CLIENT_SECRET') ?: ($_SERVER['LINKEDIN_CLIENT_SECRET'] ?? null));
$redirect_uri = (isset($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . '/linkedin/callback'; $redirect_uri = (isset($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . '/linkedin/callback';
// Exchange code for tokens // Exchange code for tokens