Updated authentication.
This commit is contained in:
parent
e74e6b1711
commit
956b132aff
1 changed files with 11 additions and 13 deletions
|
@ -16,17 +16,11 @@ class MisuzuAuth implements IAuth {
|
||||||
public function getName(): string { return 'Misuzu'; }
|
public function getName(): string { return 'Misuzu'; }
|
||||||
|
|
||||||
public function verifyToken(string $token): int {
|
public function verifyToken(string $token): int {
|
||||||
$packed = str_pad(Serialiser::uriBase64()->deserialise($token, true), 37, "\x00");
|
if(!empty($token)) {
|
||||||
$unpacked = unpack('Cversion/Nuser/H64token', $packed);
|
$method = 'Misuzu';
|
||||||
|
$signature = sprintf('verify#%s#%s#%s', $method, $token, $_SERVER['REMOTE_ADDR']);
|
||||||
|
$signature = hash_hmac('sha256', $signature, $this->secretKey);
|
||||||
|
|
||||||
if(isset($unpacked['version']) && $unpacked['version'] === 1
|
|
||||||
&& isset($unpacked['user']) && $unpacked['user'] > 0) {
|
|
||||||
$loginRequest = [
|
|
||||||
'user_id' => $unpacked['user'],
|
|
||||||
'token' => 'SESS:' . $token,
|
|
||||||
'ip' => $_SERVER['REMOTE_ADDR'],
|
|
||||||
];
|
|
||||||
$loginSignature = hash_hmac('sha256', implode('#', $loginRequest), $this->secretKey);
|
|
||||||
$login = curl_init($this->endPoint);
|
$login = curl_init($this->endPoint);
|
||||||
curl_setopt_array($login, [
|
curl_setopt_array($login, [
|
||||||
CURLOPT_AUTOREFERER => false,
|
CURLOPT_AUTOREFERER => false,
|
||||||
|
@ -34,7 +28,11 @@ class MisuzuAuth implements IAuth {
|
||||||
CURLOPT_FOLLOWLOCATION => true,
|
CURLOPT_FOLLOWLOCATION => true,
|
||||||
CURLOPT_HEADER => false,
|
CURLOPT_HEADER => false,
|
||||||
CURLOPT_POST => true,
|
CURLOPT_POST => true,
|
||||||
CURLOPT_POSTFIELDS => json_encode($loginRequest),
|
CURLOPT_POSTFIELDS => http_build_query([
|
||||||
|
'method' => $method,
|
||||||
|
'token' => $token,
|
||||||
|
'ipaddr' => $_SERVER['REMOTE_ADDR'],
|
||||||
|
], '', '&', PHP_QUERY_RFC3986),
|
||||||
CURLOPT_RETURNTRANSFER => true,
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
CURLOPT_TCP_FASTOPEN => true,
|
CURLOPT_TCP_FASTOPEN => true,
|
||||||
CURLOPT_CONNECTTIMEOUT => 2,
|
CURLOPT_CONNECTTIMEOUT => 2,
|
||||||
|
@ -43,8 +41,8 @@ class MisuzuAuth implements IAuth {
|
||||||
CURLOPT_TIMEOUT => 5,
|
CURLOPT_TIMEOUT => 5,
|
||||||
CURLOPT_USERAGENT => 'Flashii EEPROM',
|
CURLOPT_USERAGENT => 'Flashii EEPROM',
|
||||||
CURLOPT_HTTPHEADER => [
|
CURLOPT_HTTPHEADER => [
|
||||||
'Content-Type: application/json',
|
'Content-Type: application/x-www-form-urlencoded',
|
||||||
'X-SharpChat-Signature: ' . $loginSignature,
|
'X-SharpChat-Signature: ' . $signature,
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
$userInfo = json_decode(curl_exec($login));
|
$userInfo = json_decode(curl_exec($login));
|
||||||
|
|
Loading…
Reference in a new issue