From f3ec6543f11a8b51cd33d9183c8ba56757f4c8fc Mon Sep 17 00:00:00 2001 From: Anirudha Bose Date: Tue, 10 Feb 2026 21:44:41 +0530 Subject: [PATCH] [Rewards] [Uphold] Migrate OAuth endpoints to gate3 proxy (#33604) --- .../test/rewards_page_browsertest.cc | 15 +++++++++++---- build/commands/lib/config.js | 8 -------- .../rewards_protocol_navigation_throttle.cc | 7 +++++-- components/brave_rewards/core/engine/BUILD.gn | 4 ---- .../brave_rewards/core/engine/config.gni | 6 ------ .../endpoints/uphold/post_oauth_uphold.cc | 10 +++------- .../uphold/post_oauth_uphold_unittest.cc | 4 ++-- .../brave_rewards/core/engine/uphold/uphold.cc | 2 +- .../core/engine/util/environment_config.cc | 18 +++++------------- .../core/engine/util/environment_config.h | 5 ++--- .../uphold/connect_uphold_wallet.cc | 4 +--- .../uphold/connect_uphold_wallet_unittest.cc | 2 +- 12 files changed, 31 insertions(+), 54 deletions(-) diff --git a/browser/brave_rewards/test/rewards_page_browsertest.cc b/browser/brave_rewards/test/rewards_page_browsertest.cc index 38f2c65ffba..5b854a1741e 100644 --- a/browser/brave_rewards/test/rewards_page_browsertest.cc +++ b/browser/brave_rewards/test/rewards_page_browsertest.cc @@ -379,18 +379,25 @@ IN_PROC_BROWSER_TEST_F(RewardsPageBrowserTest, ConnectAccount) { std::string state; WaitForFinishNavigation([&state](const GURL& url) { std::string url_spec = url.spec(); - if (url_spec.find("/authorize/") == std::string::npos) { + if (url_spec.find("/api/oauth/uphold/sandbox/auth") == std::string::npos && + url_spec.find("/api/oauth/uphold/production/auth") == + std::string::npos) { return false; } - if (auto pos = url_spec.find("&state="); pos != std::string::npos) { - state = url_spec.substr(pos); + if (auto pos = url_spec.find("state="); pos != std::string::npos) { + pos += 6; + size_t end = url_spec.find('&', pos); + state = url_spec.substr( + pos, end != std::string::npos ? end - pos : std::string::npos); } return true; }); SetRequestHandler(base::BindLambdaForTesting( [](const GURL& url, const std::string& method) -> RequestHandlerResult { - if (url.path() == "/oauth2/token" && method == "POST") { + if ((url.path() == "/api/oauth/uphold/sandbox/token" || + url.path() == "/api/oauth/uphold/production/token") && + method == "POST") { return std::pair{200, R"({ "access_token": "abc123" })"}; } if (url.path() == "/v0/me" && method == "GET") { diff --git a/build/commands/lib/config.js b/build/commands/lib/config.js index 9eca5424719..2f3a7a8aab2 100644 --- a/build/commands/lib/config.js +++ b/build/commands/lib/config.js @@ -258,13 +258,9 @@ const Config = function () { 'updater_dev_endpoint', 'updater_prod_endpoint', 'uphold_production_api_url', - 'uphold_production_client_id', - 'uphold_production_client_secret', 'uphold_production_fee_address', 'uphold_production_oauth_url', 'uphold_sandbox_api_url', - 'uphold_sandbox_client_id', - 'uphold_sandbox_client_secret', 'uphold_sandbox_fee_address', 'uphold_sandbox_oauth_url', 'use_prebuilt_omaha4', @@ -675,13 +671,9 @@ Config.prototype.buildArgs = function () { delete args.gemini_sandbox_fee_address delete args.gemini_sandbox_oauth_url delete args.uphold_production_api_url - delete args.uphold_production_client_id - delete args.uphold_production_client_secret delete args.uphold_production_fee_address delete args.uphold_production_oauth_url delete args.uphold_sandbox_api_url - delete args.uphold_sandbox_client_id - delete args.uphold_sandbox_client_secret delete args.uphold_sandbox_fee_address delete args.uphold_sandbox_oauth_url delete args.zebpay_production_api_url diff --git a/components/brave_rewards/content/rewards_protocol_navigation_throttle.cc b/components/brave_rewards/content/rewards_protocol_navigation_throttle.cc index 62e134019a7..dda78129457 100644 --- a/components/brave_rewards/content/rewards_protocol_navigation_throttle.cc +++ b/components/brave_rewards/content/rewards_protocol_navigation_throttle.cc @@ -137,8 +137,11 @@ void MaybeLoadRewardsURL(const GURL& redirect_url, WebContents* web_contents) { GURL(brave_domains::kGate3URL), }}, {"uphold", - {GURL(BUILDFLAG(UPHOLD_PRODUCTION_OAUTH_URL)), - GURL(BUILDFLAG(UPHOLD_SANDBOX_OAUTH_URL))}}, + { + GURL(BUILDFLAG(UPHOLD_PRODUCTION_OAUTH_URL)), + GURL(BUILDFLAG(UPHOLD_SANDBOX_OAUTH_URL)), + GURL(brave_domains::kGate3URL), + }}, {"zebpay", {GURL(BUILDFLAG(ZEBPAY_PRODUCTION_OAUTH_URL)), GURL(BUILDFLAG(ZEBPAY_SANDBOX_OAUTH_URL))}}}; diff --git a/components/brave_rewards/core/engine/BUILD.gn b/components/brave_rewards/core/engine/BUILD.gn index ab5bc3ccb9a..8e07801c411 100644 --- a/components/brave_rewards/core/engine/BUILD.gn +++ b/components/brave_rewards/core/engine/BUILD.gn @@ -34,13 +34,9 @@ buildflag_header("buildflags") { "REWARDS_GRANT_STAGING_ENDPOINT=\"$rewards_grant_staging_endpoint\"", "REWARDS_GRANT_PROD_ENDPOINT=\"$rewards_grant_prod_endpoint\"", "UPHOLD_PRODUCTION_API_URL=\"$uphold_production_api_url\"", - "UPHOLD_PRODUCTION_CLIENT_ID=\"$uphold_production_client_id\"", - "UPHOLD_PRODUCTION_CLIENT_SECRET=\"$uphold_production_client_secret\"", "UPHOLD_PRODUCTION_FEE_ADDRESS=\"$uphold_production_fee_address\"", "UPHOLD_PRODUCTION_OAUTH_URL=\"$uphold_production_oauth_url\"", "UPHOLD_SANDBOX_API_URL=\"$uphold_sandbox_api_url\"", - "UPHOLD_SANDBOX_CLIENT_ID=\"$uphold_sandbox_client_id\"", - "UPHOLD_SANDBOX_CLIENT_SECRET=\"$uphold_sandbox_client_secret\"", "UPHOLD_SANDBOX_FEE_ADDRESS=\"$uphold_sandbox_fee_address\"", "UPHOLD_SANDBOX_OAUTH_URL=\"$uphold_sandbox_oauth_url\"", "ZEBPAY_PRODUCTION_API_URL=\"$zebpay_production_api_url\"", diff --git a/components/brave_rewards/core/engine/config.gni b/components/brave_rewards/core/engine/config.gni index ce680a7de87..057d16142c1 100644 --- a/components/brave_rewards/core/engine/config.gni +++ b/components/brave_rewards/core/engine/config.gni @@ -22,13 +22,9 @@ declare_args() { rewards_grant_staging_endpoint = "" rewards_grant_prod_endpoint = "" uphold_production_api_url = "" - uphold_production_client_id = "" - uphold_production_client_secret = "" uphold_production_fee_address = "" uphold_production_oauth_url = "" uphold_sandbox_api_url = "" - uphold_sandbox_client_id = "" - uphold_sandbox_client_secret = "" uphold_sandbox_fee_address = "" uphold_sandbox_oauth_url = "" zebpay_production_api_url = "" @@ -51,8 +47,6 @@ if (is_official_build) { assert(gemini_production_fee_address != "") assert(gemini_production_oauth_url != "") assert(uphold_production_api_url != "") - assert(uphold_production_client_id != "") - assert(uphold_production_client_secret != "") assert(uphold_production_fee_address != "") assert(uphold_production_oauth_url != "") assert(zebpay_production_api_url != "") diff --git a/components/brave_rewards/core/engine/endpoints/uphold/post_oauth_uphold.cc b/components/brave_rewards/core/engine/endpoints/uphold/post_oauth_uphold.cc index 903fb2d1411..bd842028633 100644 --- a/components/brave_rewards/core/engine/endpoints/uphold/post_oauth_uphold.cc +++ b/components/brave_rewards/core/engine/endpoints/uphold/post_oauth_uphold.cc @@ -8,7 +8,6 @@ #include #include -#include "base/base64.h" #include "base/json/json_reader.h" #include "brave/components/brave_rewards/core/engine/rewards_engine.h" #include "brave/components/brave_rewards/core/engine/util/environment_config.h" @@ -58,18 +57,15 @@ PostOAuthUphold::~PostOAuthUphold() = default; std::optional PostOAuthUphold::Url() const { return engine_->Get() - .uphold_api_url() - .Resolve("/oauth2/token") + .uphold_oauth_url() + .Resolve("token") .spec(); } std::optional> PostOAuthUphold::Headers( const std::string&) const { - auto& config = engine_->Get(); return std::vector{ - "Authorization: Basic " + - base::Base64Encode(base::StrCat( - {config.uphold_client_id(), ":", config.uphold_client_secret()}))}; + engine_->Get().BraveServicesKeyHeader()}; } std::optional PostOAuthUphold::Content() const { diff --git a/components/brave_rewards/core/engine/endpoints/uphold/post_oauth_uphold_unittest.cc b/components/brave_rewards/core/engine/endpoints/uphold/post_oauth_uphold_unittest.cc index 9bab2262c2b..f7b6d82ec03 100644 --- a/components/brave_rewards/core/engine/endpoints/uphold/post_oauth_uphold_unittest.cc +++ b/components/brave_rewards/core/engine/endpoints/uphold/post_oauth_uphold_unittest.cc @@ -38,8 +38,8 @@ class RewardsPostOAuthUpholdTest TEST_P(RewardsPostOAuthUpholdTest, Paths) { const auto& [ignore, status_code, body, expected_result] = GetParam(); - auto request_url = engine().Get().uphold_api_url().Resolve( - "/oauth2/token"); + auto request_url = + engine().Get().uphold_oauth_url().Resolve("token"); auto response = mojom::UrlResponse::New(); response->status_code = status_code; diff --git a/components/brave_rewards/core/engine/uphold/uphold.cc b/components/brave_rewards/core/engine/uphold/uphold.cc index daa230a9265..8e77bc87b0c 100644 --- a/components/brave_rewards/core/engine/uphold/uphold.cc +++ b/components/brave_rewards/core/engine/uphold/uphold.cc @@ -29,7 +29,7 @@ const char* Uphold::WalletType() const { } void Uphold::AssignWalletLinks(mojom::ExternalWallet& external_wallet) { - auto url = engine_->Get().uphold_oauth_url(); + auto url = engine_->Get().uphold_url(); external_wallet.account_url = url.Resolve("/dashboard").spec(); diff --git a/components/brave_rewards/core/engine/util/environment_config.cc b/components/brave_rewards/core/engine/util/environment_config.cc index 61f82d2bea8..f3f6de73546 100644 --- a/components/brave_rewards/core/engine/util/environment_config.cc +++ b/components/brave_rewards/core/engine/util/environment_config.cc @@ -73,30 +73,22 @@ GURL EnvironmentConfig::rewards_grant_url() const { } } -GURL EnvironmentConfig::uphold_oauth_url() const { +GURL EnvironmentConfig::uphold_url() const { return URLValue(current_environment() == mojom::Environment::kProduction ? BUILDFLAG(UPHOLD_PRODUCTION_OAUTH_URL) : BUILDFLAG(UPHOLD_SANDBOX_OAUTH_URL)); } +GURL EnvironmentConfig::uphold_oauth_url() const { + return BuildGate3OAuthURL("uphold"); +} + GURL EnvironmentConfig::uphold_api_url() const { return URLValue(current_environment() == mojom::Environment::kProduction ? BUILDFLAG(UPHOLD_PRODUCTION_API_URL) : BUILDFLAG(UPHOLD_SANDBOX_API_URL)); } -std::string EnvironmentConfig::uphold_client_id() const { - return current_environment() == mojom::Environment::kProduction - ? BUILDFLAG(UPHOLD_PRODUCTION_CLIENT_ID) - : BUILDFLAG(UPHOLD_SANDBOX_CLIENT_ID); -} - -std::string EnvironmentConfig::uphold_client_secret() const { - return current_environment() == mojom::Environment::kProduction - ? BUILDFLAG(UPHOLD_PRODUCTION_CLIENT_SECRET) - : BUILDFLAG(UPHOLD_SANDBOX_CLIENT_SECRET); -} - std::string EnvironmentConfig::uphold_fee_address() const { return current_environment() == mojom::Environment::kProduction ? BUILDFLAG(UPHOLD_PRODUCTION_FEE_ADDRESS) diff --git a/components/brave_rewards/core/engine/util/environment_config.h b/components/brave_rewards/core/engine/util/environment_config.h index 21f871be2e6..c1d1acfa357 100644 --- a/components/brave_rewards/core/engine/util/environment_config.h +++ b/components/brave_rewards/core/engine/util/environment_config.h @@ -30,11 +30,10 @@ class EnvironmentConfig : public RewardsEngineHelper, GURL rewards_api_url() const; GURL rewards_grant_url() const; - GURL uphold_oauth_url() const; + GURL uphold_url() const; GURL uphold_api_url() const; - std::string uphold_client_id() const; - std::string uphold_client_secret() const; std::string uphold_fee_address() const; + GURL uphold_oauth_url() const; GURL gemini_oauth_url() const; GURL gemini_api_url() const; diff --git a/components/brave_rewards/core/engine/wallet_provider/uphold/connect_uphold_wallet.cc b/components/brave_rewards/core/engine/wallet_provider/uphold/connect_uphold_wallet.cc index 4f707879c22..00be2dd1706 100644 --- a/components/brave_rewards/core/engine/wallet_provider/uphold/connect_uphold_wallet.cc +++ b/components/brave_rewards/core/engine/wallet_provider/uphold/connect_uphold_wallet.cc @@ -42,9 +42,7 @@ const char* ConnectUpholdWallet::WalletType() const { std::string ConnectUpholdWallet::GetOAuthLoginURL() const { auto& config = engine_->Get(); - auto url = config.uphold_oauth_url().Resolve( - base::StrCat({"/authorize/", config.uphold_client_id()})); - + auto url = config.uphold_oauth_url().Resolve("auth"); url = AppendOrReplaceQueryParameters( url, {{"scope", "cards:read " diff --git a/components/brave_rewards/core/engine/wallet_provider/uphold/connect_uphold_wallet_unittest.cc b/components/brave_rewards/core/engine/wallet_provider/uphold/connect_uphold_wallet_unittest.cc index 0c2c4b29f1d..b94b978fded 100644 --- a/components/brave_rewards/core/engine/wallet_provider/uphold/connect_uphold_wallet_unittest.cc +++ b/components/brave_rewards/core/engine/wallet_provider/uphold/connect_uphold_wallet_unittest.cc @@ -20,7 +20,7 @@ TEST_F(RewardsConnectUpholdWalletTest, LoginURL) { auto actual = connect.GenerateLoginURL(); auto expected_url = config.uphold_oauth_url().Resolve(base::StrCat( - {"/authorize/", config.uphold_client_id(), + {"auth" "?scope=cards%3Aread+cards%3Awrite+user%3Aread+transactions%3Aread+" "transactions%3Atransfer%3Aapplication+transactions%3Atransfer%3Aothers" "&intention=login"