Support whitelisted domains.
This commit is contained in:
parent
90ede43945
commit
ac144ce2e4
@ -1467,6 +1467,7 @@ void ConfigManager::process_app_config(tl_object_ptr<telegram_api::JSONValue> &c
|
||||
string autologin_token;
|
||||
vector<string> autologin_domains;
|
||||
vector<string> url_auth_domains;
|
||||
vector<string> whitelisted_domains;
|
||||
|
||||
vector<tl_object_ptr<telegram_api::jsonObjectValue>> new_values;
|
||||
string ignored_restriction_reasons;
|
||||
@ -1680,13 +1681,24 @@ void ConfigManager::process_app_config(tl_object_ptr<telegram_api::JSONValue> &c
|
||||
if (value->get_id() == telegram_api::jsonArray::ID) {
|
||||
auto domains = std::move(static_cast<telegram_api::jsonArray *>(value)->value_);
|
||||
for (auto &domain : domains) {
|
||||
autologin_domains.push_back(get_json_value_string(std::move(domain), key));
|
||||
url_auth_domains.push_back(get_json_value_string(std::move(domain), key));
|
||||
}
|
||||
} else {
|
||||
LOG(ERROR) << "Receive unexpected url_auth_domains " << to_string(*value);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (key == "whitelisted_domains") {
|
||||
if (value->get_id() == telegram_api::jsonArray::ID) {
|
||||
auto domains = std::move(static_cast<telegram_api::jsonArray *>(value)->value_);
|
||||
for (auto &domain : domains) {
|
||||
whitelisted_domains.push_back(get_json_value_string(std::move(domain), key));
|
||||
}
|
||||
} else {
|
||||
LOG(ERROR) << "Receive unexpected whitelisted_domains " << to_string(*value);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (key == "round_video_encoding") {
|
||||
if (value->get_id() == telegram_api::jsonObject::ID) {
|
||||
auto video_note_settings = std::move(static_cast<telegram_api::jsonObject *>(value)->value_);
|
||||
@ -1820,7 +1832,7 @@ void ConfigManager::process_app_config(tl_object_ptr<telegram_api::JSONValue> &c
|
||||
config = make_tl_object<telegram_api::jsonObject>(std::move(new_values));
|
||||
|
||||
send_closure(G()->link_manager(), &LinkManager::update_autologin_domains, std::move(autologin_token),
|
||||
std::move(autologin_domains), std::move(url_auth_domains));
|
||||
std::move(autologin_domains), std::move(url_auth_domains), std::move(whitelisted_domains));
|
||||
|
||||
Global &options = *G();
|
||||
|
||||
|
@ -754,6 +754,8 @@ void LinkManager::start_up() {
|
||||
autologin_domains_ = full_split(G()->td_db()->get_binlog_pmc()->get("autologin_domains"), '\xFF');
|
||||
|
||||
url_auth_domains_ = full_split(G()->td_db()->get_binlog_pmc()->get("url_auth_domains"), '\xFF');
|
||||
|
||||
whitelisted_domains_ = full_split(G()->td_db()->get_binlog_pmc()->get("whitelisted_domains"), '\xFF');
|
||||
}
|
||||
|
||||
void LinkManager::tear_down() {
|
||||
@ -1470,7 +1472,7 @@ unique_ptr<LinkManager::InternalLink> LinkManager::get_internal_link_passport(
|
||||
}
|
||||
|
||||
void LinkManager::update_autologin_domains(string autologin_token, vector<string> autologin_domains,
|
||||
vector<string> url_auth_domains) {
|
||||
vector<string> url_auth_domains, vector<string> whitelisted_domains) {
|
||||
autologin_update_time_ = Time::now();
|
||||
autologin_token_ = std::move(autologin_token);
|
||||
if (autologin_domains_ != autologin_domains) {
|
||||
@ -1481,6 +1483,10 @@ void LinkManager::update_autologin_domains(string autologin_token, vector<string
|
||||
url_auth_domains_ = std::move(url_auth_domains);
|
||||
G()->td_db()->get_binlog_pmc()->set("url_auth_domains", implode(url_auth_domains_, '\xFF'));
|
||||
}
|
||||
if (whitelisted_domains_ != whitelisted_domains) {
|
||||
whitelisted_domains_ = std::move(whitelisted_domains);
|
||||
G()->td_db()->get_binlog_pmc()->set("whitelisted_domains", implode(whitelisted_domains_, '\xFF'));
|
||||
}
|
||||
}
|
||||
|
||||
void LinkManager::get_deep_link_info(Slice link, Promise<td_api::object_ptr<td_api::deepLinkInfo>> &&promise) {
|
||||
@ -1510,6 +1516,9 @@ void LinkManager::get_external_link_info(string &&link, Promise<td_api::object_p
|
||||
return promise.set_value(std::move(default_result));
|
||||
}
|
||||
|
||||
bool skip_confirm = td::contains(whitelisted_domains_, r_url.ok().host_);
|
||||
default_result->skip_confirm_ = skip_confirm;
|
||||
|
||||
if (!td::contains(autologin_domains_, r_url.ok().host_)) {
|
||||
if (td::contains(url_auth_domains_, r_url.ok().host_)) {
|
||||
td_->create_handler<RequestUrlAuthQuery>(std::move(promise))->send(link, FullMessageId(), 0);
|
||||
@ -1555,7 +1564,7 @@ void LinkManager::get_external_link_info(string &&link, Promise<td_api::object_p
|
||||
|
||||
url.query_ = PSTRING() << path << parameters << added_parameter << hash;
|
||||
|
||||
promise.set_value(td_api::make_object<td_api::loginUrlInfoOpen>(url.get_url(), false));
|
||||
promise.set_value(td_api::make_object<td_api::loginUrlInfoOpen>(url.get_url(), skip_confirm));
|
||||
}
|
||||
|
||||
void LinkManager::get_login_url_info(FullMessageId full_message_id, int64 button_id,
|
||||
|
@ -60,7 +60,7 @@ class LinkManager final : public Actor {
|
||||
static unique_ptr<InternalLink> parse_internal_link(Slice link, bool is_trusted = false);
|
||||
|
||||
void update_autologin_domains(string autologin_token, vector<string> autologin_domains,
|
||||
vector<string> url_auth_domains);
|
||||
vector<string> url_auth_domains, vector<string> whitelisted_domains);
|
||||
|
||||
void get_deep_link_info(Slice link, Promise<td_api::object_ptr<td_api::deepLinkInfo>> &&promise);
|
||||
|
||||
@ -160,6 +160,7 @@ class LinkManager final : public Actor {
|
||||
vector<string> autologin_domains_;
|
||||
double autologin_update_time_ = 0.0;
|
||||
vector<string> url_auth_domains_;
|
||||
vector<string> whitelisted_domains_;
|
||||
};
|
||||
|
||||
} // namespace td
|
||||
|
Loading…
x
Reference in New Issue
Block a user