[Rewards] [Uphold] Migrate OAuth endpoints to gate3 proxy (#33604)
This commit is contained in:
@@ -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") {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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))}}};
|
||||
|
||||
@@ -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\"",
|
||||
|
||||
@@ -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 != "")
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include <optional>
|
||||
#include <utility>
|
||||
|
||||
#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<std::string> PostOAuthUphold::Url() const {
|
||||
return engine_->Get<EnvironmentConfig>()
|
||||
.uphold_api_url()
|
||||
.Resolve("/oauth2/token")
|
||||
.uphold_oauth_url()
|
||||
.Resolve("token")
|
||||
.spec();
|
||||
}
|
||||
|
||||
std::optional<std::vector<std::string>> PostOAuthUphold::Headers(
|
||||
const std::string&) const {
|
||||
auto& config = engine_->Get<EnvironmentConfig>();
|
||||
return std::vector<std::string>{
|
||||
"Authorization: Basic " +
|
||||
base::Base64Encode(base::StrCat(
|
||||
{config.uphold_client_id(), ":", config.uphold_client_secret()}))};
|
||||
engine_->Get<EnvironmentConfig>().BraveServicesKeyHeader()};
|
||||
}
|
||||
|
||||
std::optional<std::string> PostOAuthUphold::Content() const {
|
||||
|
||||
@@ -38,8 +38,8 @@ class RewardsPostOAuthUpholdTest
|
||||
TEST_P(RewardsPostOAuthUpholdTest, Paths) {
|
||||
const auto& [ignore, status_code, body, expected_result] = GetParam();
|
||||
|
||||
auto request_url = engine().Get<EnvironmentConfig>().uphold_api_url().Resolve(
|
||||
"/oauth2/token");
|
||||
auto request_url =
|
||||
engine().Get<EnvironmentConfig>().uphold_oauth_url().Resolve("token");
|
||||
|
||||
auto response = mojom::UrlResponse::New();
|
||||
response->status_code = status_code;
|
||||
|
||||
@@ -29,7 +29,7 @@ const char* Uphold::WalletType() const {
|
||||
}
|
||||
|
||||
void Uphold::AssignWalletLinks(mojom::ExternalWallet& external_wallet) {
|
||||
auto url = engine_->Get<EnvironmentConfig>().uphold_oauth_url();
|
||||
auto url = engine_->Get<EnvironmentConfig>().uphold_url();
|
||||
|
||||
external_wallet.account_url = url.Resolve("/dashboard").spec();
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
+1
-3
@@ -42,9 +42,7 @@ const char* ConnectUpholdWallet::WalletType() const {
|
||||
std::string ConnectUpholdWallet::GetOAuthLoginURL() const {
|
||||
auto& config = engine_->Get<EnvironmentConfig>();
|
||||
|
||||
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 "
|
||||
|
||||
+1
-1
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user