diff --git a/auth/oauth_microsoft.php b/auth/oauth_microsoft.php index 88a008d..b0848c3 100644 --- a/auth/oauth_microsoft.php +++ b/auth/oauth_microsoft.php @@ -24,7 +24,7 @@ $tenantId = !empty($_GET['tenant_id']) : (!empty($savedSettings['tenant_id']) ? $savedSettings['tenant_id'] : fociz_env('MICROSOFT_TENANT_ID', 'common')); if (empty($clientId)) { - header('Location: /integrations.php?error=missing_ms_client_id'); + header('Location: /integrations.php?error=' . urlencode('Vul eerst de Application (Client) ID en het Client Secret in bij de Outlook instellingen om te koppelen met Microsoft 365.')); exit; } diff --git a/integrations.php b/integrations.php index 80fa5b5..70825e0 100644 --- a/integrations.php +++ b/integrations.php @@ -3,12 +3,13 @@ * Fociz Integraties Hub (Microsoft Outlook, Microsoft Teams, Atlassian Jira) */ -require_once __DIR__ . '/includes/header.php'; +require_once __DIR__ . '/includes/auth.php'; require_once __DIR__ . '/includes/integrations/microsoft.php'; require_once __DIR__ . '/includes/integrations/jira.php'; +$user = require_auth(); $db = get_db_connection(); -$userId = $currentUser['id']; +$userId = $user['id']; $message = null; $messageType = 'success'; @@ -22,7 +23,7 @@ if (!empty($_GET['success'])) { $messageType = 'error'; } -// POST Verwerking +// POST Verwerking VÓÓR het inladen van header.php zodat HTTP redirects altijd werken if ($_SERVER['REQUEST_METHOD'] === 'POST') { $provider = strtoupper(trim($_POST['provider'] ?? '')); $action = $_POST['action'] ?? 'save'; @@ -31,18 +32,21 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { if ($action === 'disconnect') { if ($provider === 'OUTLOOK') { microsoft_disconnect($userId); - $message = "Microsoft Outlook is succesvol ontkoppeld."; + header('Location: /integrations.php?success=' . urlencode('Microsoft Outlook is succesvol ontkoppeld.')); + exit; } elseif ($provider === 'JIRA') { jira_disconnect($userId); - $message = "Atlassian Jira is succesvol ontkoppeld."; + header('Location: /integrations.php?success=' . urlencode('Atlassian Jira is succesvol ontkoppeld.')); + exit; } } - // 2. Outlook Opslaan + // 2. Outlook Opslaan of Koppelen elseif ($provider === 'OUTLOOK') { $clientId = trim($_POST['client_id'] ?? ''); $clientSecret = trim($_POST['client_secret'] ?? ''); $tenantId = trim($_POST['tenant_id'] ?? 'common'); + if (empty($tenantId)) $tenantId = 'common'; $isDemo = isset($_POST['is_demo_mode']) ? 1 : 0; // Haal bestaande tokens op @@ -71,12 +75,22 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { last_sync_at = NOW() "); $stmt->execute([$userId, $isDemo, json_encode($newSettings)]); - $message = "Instellingen voor Microsoft Outlook zijn opgeslagen."; // Als gebruiker direct op 'Koppel nu' klikte if ($action === 'connect_oauth') { - header("Location: /auth/oauth_microsoft.php?client_id=" . urlencode($clientId) . "&tenant_id=" . urlencode($tenantId)); - exit; + if (empty($clientId)) { + $message = "Vul eerst de Application (Client) ID in van uw Azure App Registratie."; + $messageType = 'error'; + } elseif (empty($clientSecret)) { + $message = "Vul eerst het Client Secret in van uw Azure App Registratie."; + $messageType = 'error'; + } else { + header("Location: /auth/oauth_microsoft.php?client_id=" . urlencode($clientId) . "&tenant_id=" . urlencode($tenantId)); + exit; + } + } else { + $message = "Instellingen voor Microsoft Outlook zijn succesvol opgeslagen."; + $messageType = 'success'; } } @@ -121,9 +135,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $accountName = $testRes['user']['displayName'] ?? 'Jira Gebruiker'; $accountId = $testRes['user']['accountId'] ?? ''; $message = "Verbinding met Jira geslaagd! Ingelogd als: {$accountName}"; + $messageType = 'success'; } } else { $message = "Jira instellingen opgeslagen."; + $messageType = 'success'; } $newSettings = [ @@ -149,6 +165,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { } } +// Laad nu pas de HTML header in +require_once __DIR__ . '/includes/header.php'; + // Haal huidige configuraties op $stmtConfigs = $db->prepare("SELECT * FROM integrations WHERE user_id = ?"); $stmtConfigs->execute([$userId]); @@ -300,42 +319,59 @@ $redirectUri = rtrim(APP_URL, '/') . '/auth/callback_microsoft.php';
Te vinden op de Overzichtspagina (Overview) van uw Azure App Registratie.
Aangemaakt onder Certificaten en geheimen > Nieuw clientgeheim (kopieer de Waarde / Value).
+ 💡 Wat moet hier staan? +
+• Laat simpelweg common staan (werkt voor elk Microsoft account).
• Of vul organizations in voor elk zakelijk Microsoft 365 werkaccount.
• U hoeft alleen uw specifieke Tenant GUID in te vullen als uw Azure app is ingesteld op Single tenant (Alleen mijn eigen organisatie).
+