From f596ec77931d80ee94f7d13713b64aad7801e863 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 19 Jan 2023 15:36:23 +0300 Subject: [PATCH] Allow to request Firebase Authentication in official apps. --- td/generate/scheme/td_api.tl | 16 +++++++++++++--- td/telegram/SendCodeHelper.cpp | 14 +++++++++++++- td/telegram/cli.cpp | 2 +- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 8c50f8040..6824c9470 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -50,12 +50,12 @@ authenticationCodeTypeMissedCall phone_number_prefix:string length:int32 = Authe //@length Length of the code authenticationCodeTypeFragment url:string length:int32 = AuthenticationCodeType; -//@description An authentication code is delivered via Firebase Authentication to the official Android app +//@description An authentication code is delivered via Firebase Authentication to the official Android application //@nonce Nonce to pass to the SafetyNet Attestation API //@length Length of the code authenticationCodeTypeFirebaseAndroid nonce:bytes length:int32 = AuthenticationCodeType; -//@description An authentication code is delivered via Firebase Authentication to the official iOS app +//@description An authentication code is delivered via Firebase Authentication to the official iOS application //@receipt Receipt of successful applikation token validation to compare with receipt from push notification //@push_timeout Time after the next authentication method is supposed to be used if verification push notification isn't received, in seconds //@length Length of the code @@ -3128,13 +3128,23 @@ callProblemPixelatedVideo = CallProblem; call id:int32 user_id:int53 is_outgoing:Bool is_video:Bool state:CallState = Call; +//@class FirebaseAuthenticationSettings @description Contains settings for Firebase Authentication in the official applications + +//@description Settings for Firebase Authentication in the official Android application +firebaseAuthenticationSettingsAndroid = FirebaseAuthenticationSettings; + +//@description Settings for Firebase Authentication in the official iOS application @device_token Device token from Apple Push Notification service @is_app_sandbox True, if App Sandbox is enabled +firebaseAuthenticationSettingsIos device_token:string is_app_sandbox:Bool = FirebaseAuthenticationSettings; + + //@description Contains settings for the authentication of the user's phone number //@allow_flash_call Pass true if the authentication code may be sent via a flash call to the specified phone number //@allow_missed_call Pass true if the authentication code may be sent via a missed call to the specified phone number //@is_current_phone_number Pass true if the authenticated phone number is used on the current device //@allow_sms_retriever_api For official applications only. True, if the application can use Android SMS Retriever API (requires Google Play Services >= 10.2) to automatically receive the authentication code from the SMS. See https://developers.google.com/identity/sms-retriever/ for more details +//@firebase_authentication_settings For official Android and iOS applications only; pass null otherwise. Settings for Firebase Authentication //@authentication_tokens List of up to 20 authentication tokens, recently received in updateOption("authentication_token") in previously logged out sessions -phoneNumberAuthenticationSettings allow_flash_call:Bool allow_missed_call:Bool is_current_phone_number:Bool allow_sms_retriever_api:Bool authentication_tokens:vector = PhoneNumberAuthenticationSettings; +phoneNumberAuthenticationSettings allow_flash_call:Bool allow_missed_call:Bool is_current_phone_number:Bool allow_sms_retriever_api:Bool firebase_authentication_settings:FirebaseAuthenticationSettings authentication_tokens:vector = PhoneNumberAuthenticationSettings; //@description Represents a reaction applied to a message @type Type of the reaction @sender_id Identifier of the chat member, applied the reaction diff --git a/td/telegram/SendCodeHelper.cpp b/td/telegram/SendCodeHelper.cpp index 97722d9b1..c078ef3e0 100644 --- a/td/telegram/SendCodeHelper.cpp +++ b/td/telegram/SendCodeHelper.cpp @@ -44,6 +44,8 @@ Result SendCodeHelper::resend_code() const { telegram_api::object_ptr SendCodeHelper::get_input_code_settings(const Settings &settings) { int32 flags = 0; vector logout_tokens; + string device_token; + bool is_app_sandbox = false; if (settings != nullptr) { if (settings->allow_flash_call_) { flags |= telegram_api::codeSettings::ALLOW_FLASHCALL_MASK; @@ -57,6 +59,16 @@ telegram_api::object_ptr SendCodeHelper::get_input_c if (settings->allow_sms_retriever_api_) { flags |= telegram_api::codeSettings::ALLOW_APP_HASH_MASK; } + if (settings->firebase_authentication_settings_ != nullptr) { + flags |= telegram_api::codeSettings::ALLOW_FIREBASE_MASK; + if (settings->firebase_authentication_settings_->get_id() == td_api::firebaseAuthenticationSettingsIos::ID) { + flags |= telegram_api::codeSettings::TOKEN_MASK; + auto ios_settings = static_cast( + settings->firebase_authentication_settings_.get()); + device_token = ios_settings->device_token_; + is_app_sandbox = ios_settings->is_app_sandbox_; + } + } constexpr size_t MAX_LOGOUT_TOKENS = 20; // server-side limit for (const auto &token : settings->authentication_tokens_) { auto r_logout_token = base64url_decode(token); @@ -73,7 +85,7 @@ telegram_api::object_ptr SendCodeHelper::get_input_c } return telegram_api::make_object(flags, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, - std::move(logout_tokens), string(), false); + std::move(logout_tokens), device_token, is_app_sandbox); } telegram_api::auth_sendCode SendCodeHelper::send_code(string phone_number, const Settings &settings, int32 api_id, diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 83be4343d..5c565451e 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -1796,7 +1796,7 @@ class CliClient final : public Actor { } td_api::object_ptr as_phone_number_authentication_settings() const { - return td_api::make_object(false, true, false, false, + return td_api::make_object(false, true, false, false, nullptr, vector(authentication_tokens_)); }