Init Git Prod Mars 2026
This commit is contained in:
commit
d81efe93b1
362 files changed
+86627
No files matched your search
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/public/includes/init_praticien.php';
|
||||
|
||||
$client_id = getenv('OUTLOOK_CLIENT_ID') ?: '2936c00e-7452-453a-af62-944cc3ad021e';
|
||||
$client_secret = getenv('OUTLOOK_CLIENT_SECRET') ?: 'H-w8Q~lpjEiDnAvP1CQwxv3IiYzfI1R2dfvCIbBM';
|
||||
$redirect_uri = 'https://uslugi.fr/outlook_callback.php';
|
||||
|
||||
if (!isset($_GET['code']) || !isset($_GET['state'])) {
|
||||
die('Code ou état manquant.');
|
||||
}
|
||||
|
||||
$code = $_GET['code'];
|
||||
$state = json_decode(base64_decode($_GET['state']), true);
|
||||
$praticien_id = $state['praticien_id'] ?? null;
|
||||
|
||||
if (!$praticien_id) {
|
||||
die('Praticien non identifié.');
|
||||
}
|
||||
|
||||
$token_url = "https://login.microsoftonline.com/consumers/oauth2/v2.0/token";
|
||||
$data = [
|
||||
'client_id' => $client_id,
|
||||
'client_secret' => $client_secret,
|
||||
'code' => $code,
|
||||
'redirect_uri' => $redirect_uri,
|
||||
'grant_type' => 'authorization_code'
|
||||
];
|
||||
|
||||
$options = [
|
||||
'http' => [
|
||||
'method' => 'POST',
|
||||
'header' => "Content-type: application/x-www-form-urlencoded",
|
||||
'content' => http_build_query($data),
|
||||
],
|
||||
];
|
||||
|
||||
$response = file_get_contents($token_url, false, stream_context_create($options));
|
||||
if (!$response) {
|
||||
die('Erreur de récupération du token Outlook.');
|
||||
}
|
||||
|
||||
$tokens = json_decode($response, true);
|
||||
$access_token = $tokens['access_token'] ?? null;
|
||||
$refresh_token = $tokens['refresh_token'] ?? null;
|
||||
$expires_in = $tokens['expires_in'] ?? 3600;
|
||||
|
||||
if (!$access_token || !$refresh_token) {
|
||||
die('Erreur de génération du token Outlook.');
|
||||
}
|
||||
|
||||
$expires_at = time() + $expires_in;
|
||||
|
||||
$pdo->prepare("INSERT INTO outlook_tokens (praticien_id, access_token, refresh_token, expires_at)
|
||||
VALUES (?, ?, ?, ?)
|
||||
ON DUPLICATE KEY UPDATE access_token = VALUES(access_token), refresh_token = VALUES(refresh_token), expires_at = VALUES(expires_at)")
|
||||
->execute([$praticien_id, $access_token, $refresh_token, $expires_at]);
|
||||
|
||||
echo <<<HTML
|
||||
<div class="container py-4 d-flex justify-content-center">
|
||||
<div class="card shadow-lg text-center" style="max-width:720px;border-radius:18px;">
|
||||
<div class="card-body p-4">
|
||||
<div class="display-6 mb-2">✅</div>
|
||||
<h2 class="h4 mb-2">Подключение к Outlook выполнено успешно</h2>
|
||||
<p class="text-muted mb-3">Теперь вы можете синхронизировать записи на приём с вашим календарём.</p>
|
||||
<a href="synchroniser_outlook.php" class="btn btn-primary btn-lg rounded-pill">
|
||||
Синхронизировать записи
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
HTML;
|
||||
?>
|
||||
Reference in new issue
Block a user