dodanie csrf, oauth 2, dockerfile

This commit is contained in:
Marcin Cieślikowski
2026-03-16 10:43:19 +01:00
parent 56c7ecff6d
commit df448ea7c1
26 changed files with 916 additions and 318 deletions
+38
View File
@@ -0,0 +1,38 @@
<?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 zostalo anulowane lub odrzucone.'));
exit();
}
if (!$expectedState || !hash_equals($expectedState, (string)$state) || $code === '') {
header('Location: login.php?oauth_error=' . urlencode('Nieprawidlowy 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 udalo sie zalogowac przez Microsoft 365.'));
exit();
}
?>