mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2026-08-13 23:13:32 +00:00
Fixed cross-datacenter WebAuthn login.
This commit is contained in:
@@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "data/data_passkey_deserialize.h"
|
||||
#include "main/main_app_config.h"
|
||||
#include "main/main_session.h"
|
||||
#include "mtproto/mtproto_auth_key.h"
|
||||
#include "platform/platform_webauthn.h"
|
||||
|
||||
namespace Data {
|
||||
@@ -165,10 +166,14 @@ void FinishPasskeyLogin(
|
||||
Fn<void(QString)> fail) {
|
||||
const auto userHandleStr = QString::fromUtf8(result.userHandle);
|
||||
const auto parts = userHandleStr.split(':');
|
||||
if (parts.size() != 2) {
|
||||
auto userDcOk = false;
|
||||
const auto userDc = (parts.size() == 2)
|
||||
? parts[0].toInt(&userDcOk)
|
||||
: 0;
|
||||
if (!userDcOk || userDc <= 0 || userDc >= MTP::kDcShift) {
|
||||
fail(u"PASSKEY_HANDLE_INVALID"_q);
|
||||
return;
|
||||
}
|
||||
const auto userDc = parts[0].toInt();
|
||||
const auto credentialIdBase64 = result.credentialId.toBase64(
|
||||
QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals);
|
||||
const auto credential = MTP_inputPasskeyCredentialPublicKey(
|
||||
@@ -181,14 +186,19 @@ void FinishPasskeyLogin(
|
||||
MTP_string(userHandleStr.toStdString())
|
||||
)
|
||||
);
|
||||
const auto flags = (userDc != initialDc)
|
||||
? MTPauth_finishPasskeyLogin::Flag::f_from_dc_id
|
||||
: MTPauth_finishPasskeyLogin::Flags(0);
|
||||
auto fromAuthKeyId = uint64(0);
|
||||
for (const auto &key : api.instance().getKeysForWrite()) {
|
||||
if (key && key->dcId() == MTP::BareDcId(initialDc)) {
|
||||
fromAuthKeyId = key->keyId();
|
||||
break;
|
||||
}
|
||||
}
|
||||
api.instance().setMainDcId(userDc);
|
||||
api.request(MTPauth_FinishPasskeyLogin(
|
||||
MTP_flags(flags),
|
||||
MTP_flags(MTPauth_finishPasskeyLogin::Flag::f_from_dc_id),
|
||||
credential,
|
||||
MTP_int(initialDc),
|
||||
MTP_long(0)
|
||||
MTP_long(int64(fromAuthKeyId))
|
||||
)).toDC(
|
||||
userDc
|
||||
).done(done).fail([=](const MTP::Error &error) {
|
||||
|
||||
Reference in New Issue
Block a user