diff --git a/composer.json b/composer.json index e5150d0..15d4f00 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,7 @@ { "require": { "flashwave/index": "^0.2410", + "flashii/apii": "^0.2", "sentry/sdk": "^4.0", "nesbot/carbon": "^3.7" }, diff --git a/composer.lock b/composer.lock index 451b020..76c1b59 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "0bd5a41ea92a75983cfabd9b9052a8a2", + "content-hash": "5bb4c1111eb08d57ef2ef77239a4ddc8", "packages": [ { "name": "carbonphp/carbon-doctrine-types", @@ -75,6 +75,43 @@ ], "time": "2024-02-09T16:56:22+00:00" }, + { + "name": "flashii/apii", + "version": "v0.2.1", + "source": { + "type": "git", + "url": "https://patchii.net/flashii/apii-php.git", + "reference": "6a93d31375dd7e75ff9264f3024f2208ce602f49" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpstan/phpstan": "^1.12", + "phpunit/phpunit": "^10.5" + }, + "type": "library", + "autoload": { + "psr-4": { + "Flashii\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "bsd-3-clause-clear" + ], + "authors": [ + { + "name": "flashwave", + "email": "packagist@flash.moe", + "homepage": "https://flash.moe", + "role": "mom" + } + ], + "description": "Client library for the Flashii.net API.", + "homepage": "https://api.flashii.net", + "time": "2024-11-16T16:03:42+00:00" + }, { "name": "flashwave/index", "version": "v0.2410.191603", diff --git a/src/Auth/AuthRoutes.php b/src/Auth/AuthRoutes.php index d25fa3e..05ee139 100644 --- a/src/Auth/AuthRoutes.php +++ b/src/Auth/AuthRoutes.php @@ -2,6 +2,8 @@ namespace EEPROM\Auth; use EEPROM\Users\UsersContext; +use Flashii\{FlashiiClient,FlashiiUrls}; +use Flashii\Credentials\{BearerCredentials,MisuzuCredentials}; use Index\Config\Config; use Index\Http\Routing\{HttpMiddleware,RouteHandler,RouteHandlerTrait}; @@ -28,16 +30,19 @@ class AuthRoutes implements RouteHandler { $authMethod = strval($authParts[0] ?? ''); $authToken = strval($authParts[1] ?? ''); - if(strcasecmp($authMethod, 'misuzu') === 0 || strcasecmp($authMethod, 'bearer') === 0) { - $authResult = ChatAuth::attempt( - $this->config->getString('endpoint'), - $authMethod, - $this->config->getString('secret'), - $authToken - ); + $isMisuzu = strcasecmp($authMethod, 'misuzu') === 0; + $isBearer = strcasecmp($authMethod, 'bearer') === 0; - if(!empty($authResult->success)) - $this->authInfo->setInfo($this->usersCtx->getUser($authResult->user_id)); + if($isMisuzu || $isBearer) { + $credentials = $isMisuzu ? new MisuzuCredentials($authToken) : new BearerCredentials($authToken); + $flashii = new FlashiiClient('EEPROM', $credentials, new FlashiiUrls( + $this->config->getString('api', FlashiiUrls::PROD_API_URL), + $this->config->getString('id', FlashiiUrls::PROD_ID_URL) + )); + + $authInfo = $flashii->v1()->me(); + if($authInfo !== null) + $this->authInfo->setInfo($this->usersCtx->getUser($authInfo->getId())); } } } diff --git a/src/Auth/ChatAuth.php b/src/Auth/ChatAuth.php deleted file mode 100644 index 4f7ba5d..0000000 --- a/src/Auth/ChatAuth.php +++ /dev/null @@ -1,53 +0,0 @@ - false, - CURLOPT_FAILONERROR => false, - CURLOPT_FOLLOWLOCATION => true, - CURLOPT_HEADER => false, - CURLOPT_POST => true, - CURLOPT_POSTFIELDS => http_build_query([ - 'method' => $method, - 'token' => $cookie, - 'ipaddr' => $_SERVER['REMOTE_ADDR'], - ], '', '&', PHP_QUERY_RFC3986), - CURLOPT_RETURNTRANSFER => true, - CURLOPT_TCP_FASTOPEN => true, - CURLOPT_CONNECTTIMEOUT => 2, - CURLOPT_MAXREDIRS => 2, - CURLOPT_PROTOCOLS => CURLPROTO_HTTPS, - CURLOPT_TIMEOUT => 5, - CURLOPT_USERAGENT => 'EEPROM', - CURLOPT_HTTPHEADER => [ - 'Content-Type: application/x-www-form-urlencoded', - 'X-SharpChat-Signature: ' . $signature, - ], - ]); - $userInfo = json_decode(curl_exec($login)); - curl_close($login); - } - - if(empty($userInfo->success)) { - $userInfo = new stdClass; - $userInfo->success = false; - $userInfo->user_id = 0; - $userInfo->username = 'Anonymous'; - $userInfo->colour_raw = 0x40000000; - $userInfo->rank = 0; - $userInfo->hierarchy = 0; - $userInfo->perms = 0; - } - - return $userInfo; - } -} diff --git a/src/EEPROMContext.php b/src/EEPROMContext.php index cdb61ec..b02d54d 100644 --- a/src/EEPROMContext.php +++ b/src/EEPROMContext.php @@ -61,7 +61,7 @@ class EEPROMContext { if($isApiDomain) { $routingCtx->register(new Auth\AuthRoutes( - $this->config->scopeTo('misuzu'), + $this->config->scopeTo('apii'), $this->authInfo, $this->usersCtx ));