Init Git Prod Mars 2026
This commit is contained in:
commit
d81efe93b1
362 files changed
+86627
No files matched your search
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
function refreshOutlookToken(PDO $pdo, int $praticien_id): ?string {
|
||||
$stmt = $pdo->prepare("SELECT refresh_token FROM outlook_tokens WHERE praticien_id = ?");
|
||||
$stmt->execute([$praticien_id]);
|
||||
$refresh_token = $stmt->fetchColumn();
|
||||
|
||||
if (!$refresh_token) return null;
|
||||
|
||||
$client_id = '8328e538-3cee-4731-9122-8b7fd6f461a9';
|
||||
$client_secret = 'xKY8Q~dygFtWlM62--4t0RVkAlFI3f5uspwOedkL';
|
||||
$token_url = 'https://login.microsoftonline.com/consumers/oauth2/v2.0/token';
|
||||
|
||||
$data = [
|
||||
'client_id' => $client_id,
|
||||
'client_secret' => $client_secret,
|
||||
'refresh_token' => $refresh_token,
|
||||
'grant_type' => 'refresh_token',
|
||||
'scope' => 'offline_access User.Read Calendars.ReadWrite'
|
||||
];
|
||||
|
||||
$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));
|
||||
$tokens = json_decode($response, true);
|
||||
|
||||
if (!isset($tokens['access_token'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$access_token = $tokens['access_token'];
|
||||
$refresh_token = $tokens['refresh_token'] ?? $refresh_token;
|
||||
$expires_at = time() + $tokens['expires_in'];
|
||||
|
||||
$pdo->prepare("UPDATE outlook_tokens SET access_token = ?, refresh_token = ?, expires_at = ? WHERE praticien_id = ?")
|
||||
->execute([$access_token, $refresh_token, $expires_at, $praticien_id]);
|
||||
|
||||
return $access_token;
|
||||
}
|
||||
Reference in new issue
Block a user