Schone start na index corruptie
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* Startpunt voor Microsoft 365 OAuth 2.0 Flow
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/../includes/auth.php';
|
||||
require_once __DIR__ . '/../includes/integrations/microsoft.php';
|
||||
|
||||
$user = require_auth();
|
||||
$db = get_db_connection();
|
||||
|
||||
// Haal centrale Microsoft app configuratie op (env of admin instellingen)
|
||||
$appConfig = microsoft_get_app_config();
|
||||
|
||||
$clientId = !empty($_GET['client_id']) ? trim($_GET['client_id']) : $appConfig['client_id'];
|
||||
$tenantId = !empty($_GET['tenant_id']) ? trim($_GET['tenant_id']) : $appConfig['tenant_id'];
|
||||
|
||||
// Voorkom AADSTS50194: single-tenant Azure applicaties mogen NOOIT het /common endpoint gebruiken
|
||||
if (empty($tenantId) || $tenantId === 'common') {
|
||||
$userEmail = $user['email'] ?? '';
|
||||
$parts = explode('@', $userEmail);
|
||||
$domain = strtolower(trim(end($parts)));
|
||||
if (!empty($domain) && !in_array($domain, ['gmail.com', 'outlook.com', 'hotmail.com', 'live.com', 'yahoo.com', 'icloud.com'])) {
|
||||
$tenantId = $domain;
|
||||
} else {
|
||||
$tenantId = 'planningsagenda.nl';
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($clientId)) {
|
||||
$err = ($user['role'] === 'ADMIN')
|
||||
? 'Vul eerst de Application (Client) ID en het Client Secret in bij het Systeembeheer om te koppelen met Microsoft 365.'
|
||||
: 'Microsoft 365 is nog niet geconfigureerd door de beheerder van uw organisatie. Vraag uw beheerder om de koppeling in te stellen.';
|
||||
header('Location: /profile.php?error=' . urlencode($err));
|
||||
exit;
|
||||
}
|
||||
|
||||
// Bepaal de dynamische of geconfigureerde redirect URI
|
||||
$redirectUri = rtrim(APP_URL, '/') . '/auth/callback_microsoft.php';
|
||||
|
||||
// Genereer cryptografisch ondertekende OAuth state waarin de user_id en timestamp veilig zijn opgeslagen
|
||||
$state = generate_oauth_state((int)$user['id']);
|
||||
$_SESSION['ms_oauth_state'] = $state;
|
||||
$_SESSION['ms_oauth_user_id'] = (int)$user['id'];
|
||||
|
||||
// Stuur gebruiker door naar Microsoft login
|
||||
$authUrl = microsoft_get_auth_url($clientId, $redirectUri, $tenantId, $state);
|
||||
header("Location: {$authUrl}");
|
||||
exit;
|
||||
|
||||
Reference in New Issue
Block a user