Files
blackwall-auth-sdk/public_html/callback.php
T
Andy Dixon f529714f45 docs: handle OAuth callback access_denied outcomes from stricter provider authz
Update SDK docs and example callback handling to process provider callback errors explicitly. access_denied is now documented and handled as an expected authorization outcome (HTTP 403), including cases where provider membership/scope checks fail at consent submission.
2026-02-26 11:36:17 +00:00

49 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
session_start();
$autoloadCandidates = [
__DIR__ . '/../vendor/autoload.php',
__DIR__ . '/../src/legacy_autoload.php',
];
foreach ($autoloadCandidates as $file) {
if (is_file($file)) {
require_once $file;
}
}
use BlackWallSDK\BlackWallAuth;
$auth = new BlackWallAuth([
'clientId' => '94d228c4-d4c6-4479-9b02-793e6a73e3f2',
'authorizeUrl' => 'https://blackwall.cx/oauth/authorize',
'tokenUrl' => 'https://blackwall.cx/oauth/token',
'userInfoUrl' => 'https://blackwall.cx/oauth/userinfo',
'redirectUri' => 'https://test.dixon.cx/callback.php',
]);
if (isset($_GET['error'])) {
$error = (string) $_GET['error'];
$description = isset($_GET['error_description']) ? (string) $_GET['error_description'] : 'Authorisation was denied.';
$status = $error === 'access_denied' ? 403 : 400;
http_response_code($status);
echo 'Authorisation failed: ' . htmlspecialchars($description, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
exit;
}
try {
$result = $auth->handleCallback($_GET);
$_SESSION['access_token'] = $result['tokens']['access_token'] ?? null;
$_SESSION['refresh_token'] = $result['tokens']['refresh_token'] ?? null;
$_SESSION['user'] = $result['raw_user'] ?? null;
header('Location: /');
exit;
} catch (Throwable $e) {
http_response_code(500);
echo 'Auth failed: ' . htmlspecialchars($e->getMessage(), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
}