'94d228c4-d4c6-4479-9b02-793e6a73e3f2', 'authorizeUrl' => 'https://blackwall.dixon.cx/oauth/authorize', 'tokenUrl' => 'https://blackwall.dixon.cx/oauth/token', 'userInfoUrl' => 'https://blackwall.dixon.cx/oauth/userinfo', 'redirectUri' => 'https://test.dixon.cx/callback.php', ]); if (!isset($_GET['code'], $_GET['state'])) { http_response_code(400); echo 'Missing code/state'; exit; } if (isset($_SESSION['blackwall_oauth_state']) && $_GET['state'] !== $_SESSION['blackwall_oauth_state']) { http_response_code(400); echo 'Invalid state'; exit; } try { $tokens = $auth->exchangeCodeForTokens($_GET['code']); $_SESSION['access_token'] = $tokens['access_token'] ?? null; $_SESSION['refresh_token'] = $tokens['refresh_token'] ?? null; if (isset($_SESSION['access_token']) && is_string($_SESSION['access_token'])) { $_SESSION['user'] = $auth->getUserInfo($_SESSION['access_token']); } unset($_SESSION['blackwall_oauth_state'], $_SESSION['blackwall_oauth_code_verifier']); header('Location: /'); exit; } catch (Throwable $e) { http_response_code(500); echo 'Auth failed: ' . htmlspecialchars($e->getMessage(), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); }