dodanie csrf, oauth 2, dockerfile
This commit is contained in:
@@ -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 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();
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user