diff --git a/web/index.php b/web/index.php new file mode 100644 index 0000000..e69de29 diff --git a/web/login/.env b/web/login/.env new file mode 100644 index 0000000..675657e --- /dev/null +++ b/web/login/.env @@ -0,0 +1,9 @@ +OIDC_CLIENT_ID=fitness-oidc +OIDC_CLIENT_SECRET=egebuqzZfVnjjBG9JDQ8tjW3TzV9gJurvT7qfB6c2SX2nPBNeaGycDfx4788QzJd +OIDC_REDIRECT_URI=https://fitness.matt-cloud.com/pgapi/auth/oidc/callback +OIDC_AUTH_ENDPOINT=https://auth.matt-cloud.com/oidc/auth +OIDC_TOKEN_ENDPOINT=https://auth.matt-cloud.com/oidc/token +OIDC_USERINFO_ENDPOINT=https://auth.matt-cloud.com/oidc/userinfo +OIDC_LOGOUT_ENDPOINT=https://auth.matt-cloud.com/logout +# Optional: the default redirect after logout +OIDC_POST_LOGOUT_REDIRECT_URI=https://fitness.matt-cloud.com/ \ No newline at end of file diff --git a/web/login/callback.php b/web/login/callback.php new file mode 100644 index 0000000..b6b1534 --- /dev/null +++ b/web/login/callback.php @@ -0,0 +1,59 @@ +exchangeCode($code); + + // Validate ID token (minimal). + $idInfo = $oidc->validateIDToken($tokens['id_token'], $nonce); + + // Get userinfo (includes groups because of scope). + $userInfo = $oidc->getUserInfo($tokens['access_token']); + + // Store everything we 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, + ]; +} catch (\Throwable $e) { + http_response_code(500); + exit('Error during OIDC exchange: ' . $e->getMessage()); +} + +// Clean up the query string (code, state) by redirecting to the home page. +header('Location: /'); +exit; \ No newline at end of file diff --git a/web/login/composer.json b/web/login/composer.json new file mode 100644 index 0000000..365b572 --- /dev/null +++ b/web/login/composer.json @@ -0,0 +1,6 @@ +{ + "require": { + "guzzlehttp/guzzle": "^7.0", + "firebase/php-jwt": "^6.0" + } +} \ No newline at end of file diff --git a/web/login/config.php b/web/login/config.php new file mode 100644 index 0000000..7495633 --- /dev/null +++ b/web/login/config.php @@ -0,0 +1,23 @@ +load(); + +/** + * Basic OIDC configuration – keep all secrets out of source‑control. + */ +define('OIDC_CLIENT_ID', getenv('OIDC_CLIENT_ID')); +define('OIDC_CLIENT_SECRET', getenv('OIDC_CLIENT_SECRET')); +define('OIDC_REDIRECT_URI', getenv('OIDC_REDIRECT_URI')); +define('OIDC_AUTH_ENDPOINT', getenv('OIDC_AUTH_ENDPOINT')); +define('OIDC_TOKEN_ENDPOINT', getenv('OIDC_TOKEN_ENDPOINT')); +define('OIDC_USERINFO_ENDPOINT', getenv('OIDC_USERINFO_ENDPOINT')); +define('OIDC_LOGOUT_ENDPOINT', getenv('OIDC_LOGOUT_ENDPOINT')); +define('OIDC_POST_LOGOUT_REDIRECT_URI', getenv('OIDC_POST_LOGOUT_REDIRECT_URI')); \ No newline at end of file diff --git a/web/login/index.php b/web/login/index.php new file mode 100644 index 0000000..1e1c6eb --- /dev/null +++ b/web/login/index.php @@ -0,0 +1,38 @@ + + + +
+ +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))?>+