Additional Improvements

This commit is contained in:
Andy Dixon
2026-03-11 07:41:21 +00:00
parent 986dc95646
commit 1d8578c1da
9 changed files with 441 additions and 49 deletions
+8 -1
View File
@@ -16,6 +16,8 @@ foreach ($autoloadCandidates as $file) {
}
use BlackWallSDK\BlackWallAuth;
use BlackWall\Auth\AuthClient;
use BlackWall\Auth\Exception\NonceMismatchException;
use BlackWall\Auth\Exception\UserInfoException;
$auth = new BlackWallAuth([
@@ -36,13 +38,18 @@ if (isset($_GET['error'])) {
}
try {
$result = $auth->handleCallback($_GET);
$result = $auth->handleCallback($_GET, true, [
'expected_nonce' => $_SESSION[AuthClient::NONCE_SESSION_KEY] ?? null,
]);
$_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 (NonceMismatchException $e) {
http_response_code(403);
echo 'Sign-in failed: the OpenID Connect nonce check did not pass. Please try signing in again.';
} catch (UserInfoException $e) {
http_response_code(403);
echo 'User info access failed: ' . htmlspecialchars($e->getMessage(), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
+5 -7
View File
@@ -16,6 +16,7 @@ foreach ($autoloadCandidates as $file) {
}
use BlackWallSDK\BlackWallAuth;
use BlackWall\Auth\AuthClient;
$auth = new BlackWallAuth([
'clientId' => '94d228c4-d4c6-4479-9b02-793e6a73e3f2',
@@ -31,19 +32,16 @@ if (isset($_GET['logout'])) {
$_SESSION['access_token'],
$_SESSION['refresh_token'],
$_SESSION['user'],
$_SESSION['blackwall_oauth_state'],
$_SESSION['blackwall_oauth_code_verifier']
$_SESSION[AuthClient::STATE_SESSION_KEY],
$_SESSION[AuthClient::CODE_VERIFIER_SESSION_KEY],
$_SESSION[AuthClient::NONCE_SESSION_KEY]
);
header('Location: /');
exit;
}
if (!isset($_SESSION['user'])) {
$authData = $auth->getAuthorizationUrl([
'extra' => [
'nonce' => rtrim(strtr(base64_encode(random_bytes(32)), '+/', '-_'), '='),
],
]);
$authData = $auth->getAuthorizationUrl();
header('Location: ' . $authData['url']);
exit;
}