Added initial ability to login with passkey.

This commit is contained in:
23rd
2025-11-30 07:44:49 +03:00
committed by John Preston
parent c70a49c0f3
commit 0480c6a4af
3 changed files with 49 additions and 3 deletions
+2
View File
@@ -378,6 +378,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_intro_qr_step2" = "Go to Settings > Devices > Link Desktop Device";
"lng_intro_qr_step3" = "Scan this image to Log In";
"lng_intro_qr_skip" = "Or log in using your phone number";
"lng_intro_qr_phone" = "Log in using phone number";
"lng_intro_qr_passkey" = "Log in using passkey";
"lng_intro_fragment_title" = "Enter code";
"lng_intro_fragment_about" = "Get the code for {phone_number} in the Anonymous Numbers section on Fragment.";
+46 -3
View File
@@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "intro/intro_qr.h"
#include "boxes/abstract_box.h"
#include "data/components/passkeys.h"
#include "intro/intro_phone.h"
#include "intro/intro_widget.h"
#include "intro/intro_password_check.h"
@@ -27,6 +28,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/update_checker.h"
#include "base/unixtime.h"
#include "qr/qr_generate.h"
#include "platform/platform_webauthn.h"
#include "styles/style_intro.h"
namespace Intro {
@@ -330,17 +332,58 @@ void QrWidget::setupControls() {
_skip = Ui::CreateChild<Ui::LinkButton>(
this,
tr::lng_intro_qr_skip(tr::now));
tr::lng_intro_qr_phone(tr::now));
if (Platform::WebAuthn::IsSupported()) {
_passkey = Ui::CreateChild<Ui::LinkButton>(
this,
tr::lng_intro_qr_passkey(tr::now));
}
rpl::combine(
sizeValue(),
_skip->widthValue()
) | rpl::start_with_next([=](QSize size, int skipWidth) {
_skip->widthValue(),
_passkey ? _passkey->widthValue() : rpl::single(0)
) | rpl::start_with_next([=](
QSize size,
int skipWidth,
int passkeyWidth) {
_skip->moveToLeft(
(size.width() - skipWidth) / 2,
contentTop() + st::introQrSkipTop);
if (_passkey) {
_passkey->moveToLeft(
(size.width() - passkeyWidth) / 2,
contentTop()
+ st::introQrSkipTop + 1.5 * st::normalFont->height);
}
}, _skip->lifetime());
_skip->setClickedCallback([=] { submit(); });
if (_passkey) {
_passkey->setClickedCallback([=] {
const auto initialDc = api().instance().mainDcId();
::Data::InitPasskeyLogin(api(), [=](
const ::Data::Passkey::LoginData &loginData) {
Platform::WebAuthn::Login(loginData, [=](
Platform::WebAuthn::LoginResult result) {
if (result.userHandle.isEmpty()) {
return;
}
::Data::FinishPasskeyLogin(
api(),
initialDc,
result,
[=](const MTPauth_Authorization &auth) { done(auth); },
[=](QString error) {
if (error == u"SESSION_PASSWORD_NEEDED"_q) {
sendCheckPasswordRequest();
} else {
showError(rpl::single(error));
}
});
});
});
});
}
}
void QrWidget::refreshCode() {
+1
View File
@@ -54,6 +54,7 @@ private:
rpl::event_stream<QByteArray> _qrCodes;
Ui::LinkButton *_skip = nullptr;
Ui::LinkButton *_passkey = nullptr;
base::Timer _refreshTimer;
mtpRequestId _requestId = 0;
bool _forceRefresh = false;