54 lines
1.9 KiB
PHP
54 lines
1.9 KiB
PHP
<?php
|
|
namespace EEPROM\Auth;
|
|
|
|
use stdClass;
|
|
|
|
final class ChatAuth {
|
|
public static function attempt(string $endPoint, string $secret, string $cookie): object {
|
|
if(!empty($cookie)) {
|
|
$method = 'Misuzu';
|
|
$signature = sprintf('verify#%s#%s#%s', $method, $cookie, $_SERVER['REMOTE_ADDR']);
|
|
$signature = hash_hmac('sha256', $signature, $secret);
|
|
|
|
$login = curl_init($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 => '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;
|
|
}
|
|
}
|