diff --git a/services/nginx/app/classes/authentication.php b/services/nginx/app/classes/authentication.php index 2a75ee8b..34c6b7db 100644 --- a/services/nginx/app/classes/authentication.php +++ b/services/nginx/app/classes/authentication.php @@ -128,11 +128,8 @@ class authentication implements authentication_i // First: try validating as a classic user auth token try { $dbToken = (new tokens_o())->getToken($token); - if ($dbToken && $dbToken->id) { - $type = $dbToken->type->value(); - if ($type === 'AUTH_TOKEN' || $type === 'AUTH_TOKEN_SUBUSER') { - return true; - } + if ($dbToken && $dbToken->id && $dbToken->type->value() === 'AUTH_TOKEN') { + return true; } } catch (Exception) { // Ignore and continue to subuser session validation @@ -171,27 +168,9 @@ class authentication implements authentication_i if (!$token->id) { return false; } - if ($token->type->value() !== 'AUTH_TOKEN' && $token->type->value() !== 'AUTH_TOKEN_SUBUSER') { + if ($token->type->value() !== 'AUTH_TOKEN') { return false; } - if ($token->type->value() === "AUTH_TOKEN_SUBUSER") { - // Get the customer number from the headers - if (!isset($headers['X-Customer-Number'])) { - return false; - } - $customer_number = (int)$headers['X-Customer-Number']; - // Resolve and validate subuser grant for the requested customer context - $subuser = (new subusers_o())->getSubuserBySessionToken($token->token->value()); - if ($subuser === null) { - return false; - } - $grants = (new subuser_grants_o())->getGrantsForSubuserAndCustomer((int)$subuser->id, $customer_number); - if (count($grants) === 0) { - return false; - } - // Get the user by the customer number - return (new users_o())->getUserByCustomerNumber($customer_number); - } // Get the user from the database $user = (new users_o())->getUserById($token->user_id->value()); $this->touchResolvedUserSession($user, $rawToken); diff --git a/services/nginx/app/objects/subusers_o.php b/services/nginx/app/objects/subusers_o.php index f7fd4b43..fb8e462f 100644 --- a/services/nginx/app/objects/subusers_o.php +++ b/services/nginx/app/objects/subusers_o.php @@ -320,9 +320,6 @@ class subusers_o extends db $session_token = bin2hex(random_bytes(32)); $this->cache('session_token:' . $session_token, $this->id, 'subuser_sessions'); $this->setCachedExpiration('session_token:' . $session_token, 7 * 24 * 60 * 60, 'subuser_sessions'); // Set the session to expire after 7 days - // Add the token - $tokens_o = new tokens_o(); - $tokens_o->create($this->id, $session_token, 'AUTH_TOKEN_SUBUSER'); return $session_token; } @@ -346,22 +343,6 @@ class subusers_o extends db $subuser->getObjectProperties(); return $subuser; } - // Fallback: resolve via tokens table if cache is missing/expired - try { - // tokens_o::getToken() might throw Exception if not found - $tok = (new tokens_o())->getToken($token); - if ($tok && $tok->id && $tok->type->value() === 'AUTH_TOKEN_SUBUSER') { - $resolvedId = (int)$tok->user_id->value(); - // Re-cache mapping for future lookups (7 days to match session lifetime) - $this->cache($cache_key, $resolvedId, $cache_object_id); - $this->setCachedExpiration($cache_key, 7 * 24 * 60 * 60, $cache_object_id); - $subuser = (new subusers_o())->select($resolvedId); - $subuser->getObjectProperties(); - return $subuser; - } - } catch (Exception $e) { - // Token not found or other error; treat as missing - } return null; }