From f2810a79506753a509a84d048a08037b08308f18 Mon Sep 17 00:00:00 2001 From: matt Date: Fri, 23 Oct 2026 03:25:45 -0700 Subject: [PATCH] OIDC test - move to www base --- Dockerfile | 13 ++ web/login/.env | 9 -- web/login/callback.php | 59 -------- web/login/composer.json | 6 - web/login/config.php | 23 --- web/login/index.php | 38 ----- web/login/login.php | 18 --- web/login/logout.php | 15 -- web/login/src/OIDC.php | 91 ------------ web/photos-old.php | 38 ----- web/photos.php | 314 ---------------------------------------- web/test.html | 114 --------------- 12 files changed, 13 insertions(+), 725 deletions(-) delete mode 100644 web/login/.env delete mode 100644 web/login/callback.php delete mode 100644 web/login/composer.json delete mode 100644 web/login/config.php delete mode 100644 web/login/index.php delete mode 100644 web/login/login.php delete mode 100644 web/login/logout.php delete mode 100644 web/login/src/OIDC.php delete mode 100644 web/photos-old.php delete mode 100644 web/photos.php delete mode 100644 web/test.html diff --git a/Dockerfile b/Dockerfile index 6350961..1858b5c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,13 +10,26 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ supervisor \ # Others net-tools curl less nano \ + # PHP extensions needed by the OIDC helpers + libzip-dev libpng-dev libicu-dev libpq-dev \ + && docker-php-ext-install pdo_mysql \ + && docker-php-ext-install zip \ + && docker-php-ext-install intl \ # Clean up && rm -rf /var/lib/apt/lists/* +# ------------------------------------------------------------- +# Install Composer (stand‑alone) +# ------------------------------------------------------------- +RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer + # Apache on 8069 COPY apache_ports.conf /etc/apache2/ports.conf COPY apache_vhost.conf /etc/apache2/sites-available/000-default.conf COPY web/ /var/www/html/ +# Set up composer +WORKDIR /var/www/html/ +RUN composer install --no-dev --optimize-autoloader --no-interaction # API on 5000 RUN mkdir -p /opt/Fitness diff --git a/web/login/.env b/web/login/.env deleted file mode 100644 index 675657e..0000000 --- a/web/login/.env +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index b6b1534..0000000 --- a/web/login/callback.php +++ /dev/null @@ -1,59 +0,0 @@ -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 deleted file mode 100644 index 365b572..0000000 --- a/web/login/composer.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "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 deleted file mode 100644 index 7495633..0000000 --- a/web/login/config.php +++ /dev/null @@ -1,23 +0,0 @@ -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 deleted file mode 100644 index 1e1c6eb..0000000 --- a/web/login/index.php +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - Fitness Site – OIDC Demo - - - -

Fitness Site – OIDC Demo

- - -

You are not logged in.

-

- -

Logged in as:

- -
-

User Information

-
-
- -
-

ID Token Payload (claims)

-
-
- -

- - - \ No newline at end of file diff --git a/web/login/login.php b/web/login/login.php deleted file mode 100644 index 0f22b2b..0000000 --- a/web/login/login.php +++ /dev/null @@ -1,18 +0,0 @@ -buildAuthUrl($state, $nonce)); -exit; \ No newline at end of file diff --git a/web/login/logout.php b/web/login/logout.php deleted file mode 100644 index b134ec8..0000000 --- a/web/login/logout.php +++ /dev/null @@ -1,15 +0,0 @@ -http = new Client(['http_errors' => false]); - } - - /** - * Build the Auth URL that redirects the user to Authelia. - */ - public function buildAuthUrl(string $state, string $nonce): string - { - $params = [ - 'response_type' => 'code', - 'client_id' => OIDC_CLIENT_ID, - 'redirect_uri' => OIDC_REDIRECT_URI, - 'scope' => 'openid profile email groups', - 'state' => $state, - 'nonce' => $nonce, - ]; - - return OIDC_AUTH_ENDPOINT . '?' . http_build_query($params); - } - - /** - * Exchange the Authorization Code for tokens. - */ - public function exchangeCode(string $code): array - { - $response = $this->http->post(OIDC_TOKEN_ENDPOINT, [ - 'auth' => [OIDC_CLIENT_ID, OIDC_CLIENT_SECRET], - 'form_params' => [ - 'grant_type' => 'authorization_code', - 'code' => $code, - 'redirect_uri' => OIDC_REDIRECT_URI, - ], - ]); - - if ($response->getStatusCode() !== 200) { - throw new \RuntimeException('Token endpoint returned ' . $response->getStatusCode()); - } - - return json_decode((string)$response->getBody(), true, 512, JSON_THROW_ON_ERROR); - } - - /** - * Call /userinfo with the access token. - */ - public function getUserInfo(string $accessToken): array - { - $response = $this->http->get(OIDC_USERINFO_ENDPOINT, [ - 'headers' => [ - 'Authorization' => 'Bearer ' . $accessToken, - ], - ]); - - if ($response->getStatusCode() !== 200) { - throw new \RuntimeException('Userinfo endpoint returned ' . $response->getStatusCode()); - } - - return json_decode((string)$response->getBody(), true, 512, JSON_THROW_ON_ERROR); - } - - /** - * Validate the ID Token (minimal validation for demo purposes). - */ - public function validateIDToken(string $idToken, string $nonce): array - { - // Authelia uses RS256 by default, but your config says "none". - // We'll decode without verification if alg is "none". - $decoded = JWT::decode($idToken, new Key('', ''), ['none', 'RS256']); - - // Check nonce matches what we stored in session. - if ($decoded->nonce !== $nonce) { - throw new \RuntimeException('Invalid nonce'); - } - - return (array)$decoded; - } -} \ No newline at end of file diff --git a/web/photos-old.php b/web/photos-old.php deleted file mode 100644 index a90dd79..0000000 --- a/web/photos-old.php +++ /dev/null @@ -1,38 +0,0 @@ - - -
- Drag photo here or click to choose -
- - \ No newline at end of file diff --git a/web/photos.php b/web/photos.php deleted file mode 100644 index 9829887..0000000 --- a/web/photos.php +++ /dev/null @@ -1,314 +0,0 @@ -getMessage(), E_USER_WARNING); -} - -// Check upload permissions -$has_upload_perm = true; // Add authorization logic here - -// Generate unique token for upload (security) -$upload_token = bin2hex(random_bytes(16)); -?> - - - - - - - Photos for Service Provider #<?php echo htmlspecialchars($provider_id); ?> - - - -

Photos for Service Provider #

- - -
- -
- - - -
- - -
-
- -

Upload permissions disabled. Contact administrator.

- - -
- Loading photos... -
- - - - - - \ No newline at end of file diff --git a/web/test.html b/web/test.html deleted file mode 100644 index c117c95..0000000 --- a/web/test.html +++ /dev/null @@ -1,114 +0,0 @@ - - - - - Fitness Tracker - - - - -

Providers

- - - - -
IDNamePhonePhoto
- - - - - - - \ No newline at end of file