OIDC test - test jumbojett oidc php app

This commit is contained in:
matt committed 2026-10-23 04:38:37 -07:00
1 parent a759eb206f
commit 97a31db020
6 files changed
+79 -98

No files matched your search

+26 -45
View File
@@ -1,59 +1,40 @@
<?php
declare(strict_types=1);
require_once __DIR__ . '/config.php';
require_once __DIR__ . '/vendor/autoload.php';
// callback.php
require __DIR__ . '/../vendor/autoload.php';
session_start();
use Fitness\OIDC\OIDC;
// Ensure a state was sent back.
if (!isset($_GET['state']) || !isset($_SESSION['oidc_state'])) {
http_response_code(400);
exit('Missing state parameter.');
}
// Verify the state matches what we stored.
if ($_GET['state'] !== $_SESSION['oidc_state']) {
http_response_code(400);
exit('Invalid state.');
}
// Clean up the session variables.
$state = $_SESSION['oidc_state'];
$nonce = $_SESSION['oidc_nonce'];
unset($_SESSION['oidc_state'], $_SESSION['oidc_nonce']);
if (!isset($_GET['code'])) {
http_response_code(400);
exit('Missing authorization code.');
}
$code = $_GET['code'];
$oidc = new OIDC();
$oidc = new \Jumbojett\OpenIDConnectClient(
'https://auth.matt-cloud.com/oidc',
'fitness-oidc',
'egebuqzZfVnjjBG9JDQ8tjW3TzV9gJurvT7qfB6c2SX2nPBNeaGycDfx4788QzJd'
);
$oidc->setRedirectURL('https://fitness.matt-cloud.com/pgapi/auth/oidc/callback');
try {
// Exchange code for tokens.
$tokens = $oidc->exchangeCode($code);
// Finish the auth flow – exchanges the code, validates the ID‑token, fetches userinfo
$oidc->authenticate();
// Validate ID token (minimal).
$idInfo = $oidc->validateIDToken($tokens['id_token'], $nonce);
// $oidc->idToken is a JWT object; you can cast to array if needed
$idToken = $oidc->idToken;
// Get userinfo (includes groups because of scope).
$userInfo = $oidc->getUserInfo($tokens['access_token']);
// Userinfo (includes groups because you requested the `groups` scope)
$userInfo = $oidc->getUserInfo(); // or $oidc->requestUserInfo('email')
// Store everything we need in the session.
// Store what you need in the session
$_SESSION['user'] = [
'id_token' => $tokens['id_token'],
'access_token'=> $tokens['access_token'],
'refresh_token'=> $tokens['refresh_token'] ?? null,
'expires_in' => $tokens['expires_in'] ?? null,
'id_info' => $idInfo,
'user_info' => $userInfo,
'id_token' => $oidc->idToken, // JWT string
'access_token'=> $oidc->accessToken, // opaque or JWT
'refresh_token'=> $oidc->refreshToken,
'expires_in' => $oidc->expiresIn,
'claims' => (array)$idToken, // decoded claims
'userinfo' => $userInfo,
];
} catch (\Throwable $e) {
} catch (Exception $e) {
http_response_code(500);
exit('Error during OIDC exchange: ' . $e->getMessage());
echo "Authentication failed: " . $e->getMessage();
exit;
}
// Clean up the query string (code, state) by redirecting to the home page.
// Redirect to the site’s landing page
header('Location: /');
exit;