diff --git a/README.md b/README.md index 1d4d6c0..2081eef 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,10 @@ This app is intended to use with tracking personal fitness providers and visits I will build this with LAPP stack - Linux, Apache, PHP & Python. I will build the front-end in PHP, and the back-end will be a Python API with a database. The database will be a SQLite file handled by the Python service. There will need to be a Users table, a Providers table, and a Visits table. The Users table will contain the information and settings for the site users. The settings can be a JSON structure inside a single text entry. The Providers table will track the Providers info and rates. The rates will also be a JSON structure in a single text field. Any user can add a provider, and set it private or not. If not private, other users can add visits for the same provider. The Visits table will contain enties for User Visits to Providers. This will have date, time, location, provider, cost. There should be a initialize_db function that checks for the file and creates it if needed, including all tables. Here is a complete list of data for each table. + +Found this for OIDC - don't wanna lose it +https://github.com/jumbojett/OpenID-Connect-PHP/blob/master/README.md + ``` Users - Name diff --git a/web/callback.php b/web/callback.php index b6b1534..bf058e1 100644 --- a/web/callback.php +++ b/web/callback.php @@ -1,59 +1,40 @@ 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; \ No newline at end of file diff --git a/web/composer.json b/web/composer.json index 09fd932..c08ba4a 100644 --- a/web/composer.json +++ b/web/composer.json @@ -1,5 +1,6 @@ { "require": { + "jumbojett/openid-connect-php": "^2.4", "vlucas/phpdotenv": "^5.4", "guzzlehttp/guzzle": "^7.0", "firebase/php-jwt": "^7.0" diff --git a/web/index.php b/web/index.php index 1e1c6eb..8f4a923 100644 --- a/web/index.php +++ b/web/index.php @@ -1,38 +1,19 @@ - -
- -Email: = htmlspecialchars($_SESSION['user']['userinfo']['email'] ?? '') ?>
+Groups: = htmlspecialchars(implode(', ', $_SESSION['user']['userinfo']['groups'] ?? [])) ?>
+JWT claims:
= htmlspecialchars(print_r($_SESSION['user']['claims'], true)) ?>- -
You are not logged in.
- - -Logged in as: =htmlspecialchars($_SESSION['user']['user_info']['name'] ?? 'N/A')?>
- -=htmlspecialchars(json_encode($_SESSION['user']['user_info'], JSON_PRETTY_PRINT))?>-
=htmlspecialchars(json_encode($_SESSION['user']['id_info'], JSON_PRETTY_PRINT))?>-