OIDC test - test jumbojett oidc round two 1
This commit is contained in:
1 parent
6f8dd7bbe3
commit
65a69b585d
9 files changed
+85
-226
No files matched your search
+22
-29
@@ -1,40 +1,33 @@
|
||||
<?php
|
||||
// callback.php
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
use Jumbojett\OpenIDConnectClient;
|
||||
|
||||
session_start();
|
||||
$config = require __DIR__ . '/../config.php';
|
||||
|
||||
$oidc = new \Jumbojett\OpenIDConnectClient(
|
||||
'https://auth.matt-cloud.com/oidc',
|
||||
'fitness-oidc',
|
||||
'egebuqzZfVnjjBG9JDQ8tjW3TzV9gJurvT7qfB6c2SX2nPBNeaGycDfx4788QzJd'
|
||||
$oidc = new OpenIDConnectClient(
|
||||
$config['provider_url'],
|
||||
$config['client_id'],
|
||||
$config['client_secret']
|
||||
);
|
||||
$oidc->setRedirectURL('https://fitness.matt-cloud.com/pgapi/auth/oidc/callback');
|
||||
$oidc->setRedirectURL($config['redirect_uri']);
|
||||
$oidc->addScope($config['scopes']);
|
||||
$oidc->setResponseTypes([$config['response_type']]);
|
||||
|
||||
try {
|
||||
// Finish the auth flow – exchanges the code, validates the ID‑token, fetches userinfo
|
||||
$oidc->authenticate();
|
||||
// This will read the `code` query parameter, fetch the tokens
|
||||
// and validate everything.
|
||||
$oidc->authenticate();
|
||||
|
||||
// $oidc->idToken is a JWT object; you can cast to array if needed
|
||||
$idToken = $oidc->idToken;
|
||||
|
||||
// Userinfo (includes groups because you requested the `groups` scope)
|
||||
$userInfo = $oidc->getUserInfo(); // or $oidc->requestUserInfo('email')
|
||||
// Fetch the OpenID Connect userinfo claims
|
||||
$claims = $oidc->requestUserInfo(); // → stdClass with the claims
|
||||
|
||||
// Store what you need in the session
|
||||
$_SESSION['user'] = [
|
||||
'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 (Exception $e) {
|
||||
http_response_code(500);
|
||||
echo "Authentication failed: " . $e->getMessage();
|
||||
exit;
|
||||
}
|
||||
// Store what we need in the PHP session
|
||||
$_SESSION['authenticated'] = true;
|
||||
$_SESSION['name'] = $claims->name ?? $claims->given_name ?? $claims->family_name ?? '';
|
||||
$_SESSION['email'] = $claims->email ?? '';
|
||||
$_SESSION['groups'] = $claims->groups ?? [];
|
||||
|
||||
// Redirect to the site’s landing page
|
||||
header('Location: /');
|
||||
// Redirect back to the home page
|
||||
header('Location: ../');
|
||||
exit;
|
||||
Reference in new issue
Block a user