Replaced ChatAuth with public API auth.
This commit is contained in:
parent
6dc0ccd9bf
commit
ada2baee17
5 changed files with 61 additions and 77 deletions
|
@ -1,6 +1,7 @@
|
|||
{
|
||||
"require": {
|
||||
"flashwave/index": "^0.2410",
|
||||
"flashii/apii": "^0.2",
|
||||
"erusev/parsedown": "~1.6",
|
||||
"sentry/sdk": "^4.0"
|
||||
},
|
||||
|
|
39
composer.lock
generated
39
composer.lock
generated
|
@ -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": "0fcc2129a9e1c99597116e91c7bb2df1",
|
||||
"content-hash": "f71663659023233c6bbd47cc74f1d954",
|
||||
"packages": [
|
||||
{
|
||||
"name": "erusev/parsedown",
|
||||
|
@ -56,6 +56,43 @@
|
|||
},
|
||||
"time": "2019-12-30T22:54:17+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",
|
||||
|
|
|
@ -1,24 +1,29 @@
|
|||
<?php
|
||||
namespace Seria;
|
||||
|
||||
use Seria\Auth\ChatAuth;
|
||||
use Flashii\{FlashiiClient,FlashiiUrls};
|
||||
use Flashii\Credentials\MisuzuCredentials;
|
||||
use Seria\Users\UserInfo;
|
||||
|
||||
require_once __DIR__ . '/../seria.php';
|
||||
|
||||
$authToken = (string)filter_input(INPUT_COOKIE, 'msz_auth');
|
||||
$authInfo = ChatAuth::attempt($cfg->scopeTo('cauth'), $authToken);
|
||||
$flashii = new FlashiiClient('Seria', new MisuzuCredentials($authToken), new FlashiiUrls(
|
||||
$cfg->getString('apii:api', FlashiiUrls::PROD_API_URL),
|
||||
$cfg->getString('apii:id', FlashiiUrls::PROD_ID_URL)
|
||||
));
|
||||
$authInfo = $flashii->v1()->me();
|
||||
|
||||
if($authInfo->success) {
|
||||
if($authInfo !== null) {
|
||||
$users = $seria->getUsersContext()->getUsers();
|
||||
$users->syncChatUser($authInfo);
|
||||
$sUserInfo = $users->getUser($authInfo->user_id, 'id');
|
||||
$users->syncApiUser($authInfo);
|
||||
$sUserInfo = $users->getUser($authInfo->getId(), 'id');
|
||||
$seria->getAuthInfo()->setInfo($sUserInfo);
|
||||
} else $sUserInfo = null;
|
||||
|
||||
$seria->startCSRFP(
|
||||
$cfg->getString('csrfp:secret', 'mewow'),
|
||||
$authInfo->success ? $authToken : (string)filter_input(INPUT_SERVER, 'REMOTE_ADDR')
|
||||
$authInfo === null ? (string)filter_input(INPUT_SERVER, 'REMOTE_ADDR') : $authToken
|
||||
);
|
||||
|
||||
$seria->startTemplating();
|
||||
|
|
|
@ -1,55 +0,0 @@
|
|||
<?php
|
||||
namespace Seria\Auth;
|
||||
|
||||
use stdClass;
|
||||
use Index\Config\Config;
|
||||
|
||||
final class ChatAuth {
|
||||
public static function attempt(Config $config, string $cookie): object {
|
||||
if(!empty($cookie)) {
|
||||
$method = 'Misuzu';
|
||||
$signature = sprintf('verify#%s#%s#%s', $method, $cookie, $_SERVER['REMOTE_ADDR']);
|
||||
$signature = hash_hmac('sha256', $signature, $config->getString('secret'));
|
||||
|
||||
$login = curl_init($config->getString('endpoint'));
|
||||
curl_setopt_array($login, [
|
||||
CURLOPT_AUTOREFERER => 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 => 'Seria',
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ namespace Seria\Users;
|
|||
|
||||
use InvalidArgumentException;
|
||||
use RuntimeException;
|
||||
use Flashii\V1\Users\V1User;
|
||||
use Index\XString;
|
||||
use Index\Colour\Colour;
|
||||
use Index\Db\{DbConnection,DbStatementCache};
|
||||
|
@ -18,21 +19,16 @@ class Users {
|
|||
return XString::random(48);
|
||||
}
|
||||
|
||||
public function syncChatUser(object $authInfo): void {
|
||||
if(!$authInfo->success)
|
||||
return;
|
||||
|
||||
$userColourFixed = /*($authInfo->colour_raw & 0x40000000) ? null :*/ $authInfo->colour_raw;
|
||||
$stmt = $this->cache->get('INSERT INTO ser_users (user_id, user_name, user_colour, user_rank, user_permissions) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE user_name = ?, user_colour = ?, user_rank = ?, user_permissions = ?');
|
||||
$stmt->addParameter(1, $authInfo->user_id);
|
||||
$stmt->addParameter(2, $authInfo->username);
|
||||
$stmt->addParameter(3, $userColourFixed);
|
||||
$stmt->addParameter(4, $authInfo->rank);
|
||||
$stmt->addParameter(5, $authInfo->perms);
|
||||
$stmt->addParameter(6, $authInfo->username);
|
||||
$stmt->addParameter(7, $userColourFixed);
|
||||
$stmt->addParameter(8, $authInfo->rank);
|
||||
$stmt->addParameter(9, $authInfo->perms);
|
||||
public function syncApiUser(V1User $authInfo): void {
|
||||
$userColourUnfixed = $authInfo->getColourRaw() ?? 0x40000000;
|
||||
$stmt = $this->cache->get('INSERT INTO ser_users (user_id, user_name, user_colour, user_rank, user_permissions) VALUES (?, ?, ?, ?, 0) ON DUPLICATE KEY UPDATE user_name = ?, user_colour = ?, user_rank = ?');
|
||||
$stmt->nextParameter($authInfo->getId());
|
||||
$stmt->nextParameter($authInfo->getName());
|
||||
$stmt->nextParameter($userColourUnfixed);
|
||||
$stmt->nextParameter($authInfo->getRank());
|
||||
$stmt->nextParameter($authInfo->getName());
|
||||
$stmt->nextParameter($userColourUnfixed);
|
||||
$stmt->nextParameter($authInfo->getRank());
|
||||
$stmt->execute();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue