You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.1 KiB
PHP
39 lines
1.1 KiB
PHP
<?php
|
|
require_once 'includes/oauth_microsoft.php';
|
|
|
|
if (!isMicrosoftOAuthConfigured()) {
|
|
http_response_code(503);
|
|
exit('Logowanie Microsoft nie jest skonfigurowane.');
|
|
}
|
|
|
|
$expectedState = $_SESSION['microsoft_oauth_state'] ?? null;
|
|
$state = $_GET['state'] ?? '';
|
|
$code = $_GET['code'] ?? '';
|
|
$error = $_GET['error'] ?? '';
|
|
|
|
unset($_SESSION['microsoft_oauth_state']);
|
|
|
|
if ($error !== '') {
|
|
header('Location: login.php?oauth_error=' . urlencode('Logowanie Microsoft zostało anulowane lub odrzucone.'));
|
|
exit();
|
|
}
|
|
|
|
if (!$expectedState || !hash_equals($expectedState, (string)$state) || $code === '') {
|
|
header('Location: login.php?oauth_error=' . urlencode('Nieprawidłowy stan logowania Microsoft.'));
|
|
exit();
|
|
}
|
|
|
|
try {
|
|
$tokens = exchangeMicrosoftCodeForTokens($code);
|
|
$identity = extractMicrosoftIdentity($tokens);
|
|
$user = findOrProvisionMicrosoftUser($pdo, $identity);
|
|
loginUserIntoSession($user);
|
|
header('Location: index.php');
|
|
exit();
|
|
} catch (Throwable $e) {
|
|
error_log($e->getMessage());
|
|
header('Location: login.php?oauth_error=' . urlencode('Nie udało się zalogować przez Microsoft 365.'));
|
|
exit();
|
|
}
|
|
?>
|