mirror of
https://github.com/openvk/openvk
synced 2024-12-23 00:51:03 +03:00
VKAPI: Fix 2FA compatibility with alternative clients
VKAPI: Fix crash when trying to call Messages.getConversations method
This commit is contained in:
parent
eb857d2e55
commit
f5bec29bf6
2 changed files with 25 additions and 3 deletions
|
@ -220,7 +220,7 @@ final class Messages extends VKAPIRequestHandler
|
|||
return (object) [
|
||||
"count" => sizeof($list),
|
||||
"items" => $list,
|
||||
"profiles" => (new APIUsers)->get(implode(',', $users), $fields, $offset, $count)
|
||||
"profiles" => (!empty($users) ? (new APIUsers)->get(implode(',', $users), $fields, $offset, $count) : [])
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,6 +43,24 @@ final class VKAPIPresenter extends OpenVKPresenter
|
|||
exit(json_encode($payload));
|
||||
}
|
||||
|
||||
private function twofaFail(int $userId): void
|
||||
{
|
||||
header("HTTP/1.1 401 Unauthorized");
|
||||
header("Content-Type: application/json");
|
||||
|
||||
$payload = [
|
||||
"error" => "need_validation",
|
||||
"error_description" => "use app code",
|
||||
"validation_type" => "2fa_app",
|
||||
"validation_sid" => "2fa_".$userId."_2839041_randommessdontread",
|
||||
"phone_mask" => "+374 ** *** 420",
|
||||
"redirect_url" => "https://http.cat/418", // Not implemented yet :( So there is a photo of cat :3
|
||||
"validation_resend" => "nowhere"
|
||||
];
|
||||
|
||||
exit(json_encode($payload));
|
||||
}
|
||||
|
||||
private function badMethod(string $object, string $method): void
|
||||
{
|
||||
$this->fail(3, "Unknown method passed.", $object, $method);
|
||||
|
@ -249,8 +267,12 @@ final class VKAPIPresenter extends OpenVKPresenter
|
|||
$user = (new Users)->get($uId);
|
||||
|
||||
$code = $this->requestParam("code");
|
||||
if($user->is2faEnabled() && !($code === (new Totp)->GenerateToken(Base32::decode($user->get2faSecret())) || $user->use2faBackupCode((int) $code)))
|
||||
if($user->is2faEnabled() && !($code === (new Totp)->GenerateToken(Base32::decode($user->get2faSecret())) || $user->use2faBackupCode((int) $code))) {
|
||||
if($this->requestParam("2fa_supported") == "1")
|
||||
$this->twofaFail($user->getId());
|
||||
else
|
||||
$this->fail(28, "Invalid 2FA code", "internal", "acquireToken");
|
||||
}
|
||||
|
||||
$token = new APIToken;
|
||||
$token->setUser($user);
|
||||
|
|
Loading…
Reference in a new issue