#include "google_apis/gaia/gaia_auth_fetcher.h"
#include <optional>
#include <string>
#include <utility>
#include <vector>
#include "base/functional/bind.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/user_metrics.h"
#include "base/metrics/user_metrics_action.h"
#include "base/strings/escape.h"
#include "base/strings/strcat.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/system/sys_info.h"
#include "base/types/optional_util.h"
#include "base/values.h"
#include "google_apis/credentials_mode.h"
#include "google_apis/gaia/gaia_auth_consumer.h"
#include "google_apis/gaia/gaia_auth_util.h"
#include "google_apis/gaia/gaia_constants.h"
#include "google_apis/gaia/gaia_urls.h"
#include "google_apis/gaia/google_service_auth_error.h"
#include "google_apis/gaia/oauth2_id_token_decoder.h"
#include "google_apis/gaia/oauth_multilogin_result.h"
#include "net/base/isolation_info.h"
#include "net/http/http_response_headers.h"
#include "net/http/http_status_code.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
namespace {
const size_t kMaxMessageSize = …;
constexpr char kBadAuthenticationError[] = …;
constexpr char kBadAuthenticationShortError[] = …;
constexpr char kServiceUnavailableError[] = …;
constexpr char kServiceUnavailableShortError[] = …;
constexpr char kFormEncodedContentType[] = …;
constexpr char kJsonContentType[] = …;
std::unique_ptr<const GaiaAuthConsumer::ClientOAuthResult>
ExtractOAuth2TokenPairResponse(const std::string& data) { … }
GaiaAuthConsumer::TokenRevocationStatus
GetTokenRevocationStatusFromResponseData(const std::string& data,
int response_code) { … }
base::Value::Dict ParseJSONDict(const std::string& data) { … }
GaiaAuthConsumer::ReAuthProofTokenStatus ErrorMessageToReAuthProofTokenStatus(
const std::string& message) { … }
}
namespace gaia {
GaiaSource::GaiaSource(Type type) : … { … }
GaiaSource::GaiaSource(Type type, const std::string& suffix)
: … { … }
void GaiaSource::SetGaiaSourceSuffix(const std::string& suffix) { … }
std::string GaiaSource::ToString() { … }
}
const char GaiaAuthFetcher::kOAuth2CodeToTokenPairBodyFormat[] = …;
const char GaiaAuthFetcher::kOAuth2CodeToTokenPairDeviceIdParam[] = …;
const char
GaiaAuthFetcher::kOAuth2CodeToTokenPairBindingRegistrationTokenParam[] = …;
const char GaiaAuthFetcher::kOAuth2RevokeTokenBodyFormat[] = …;
const char GaiaAuthFetcher::kErrorParam[] = …;
const char GaiaAuthFetcher::kErrorUrlParam[] = …;
const char GaiaAuthFetcher::kOAuthHeaderFormat[] = …;
const char GaiaAuthFetcher::kOAuthMultiBearerHeaderFormat[] = …;
GaiaAuthFetcher::GaiaAuthFetcher(
GaiaAuthConsumer* consumer,
gaia::GaiaSource source,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory)
: … { … }
GaiaAuthFetcher::~GaiaAuthFetcher() = default;
bool GaiaAuthFetcher::HasPendingFetch() { … }
void GaiaAuthFetcher::SetPendingFetch(bool pending_fetch) { … }
bool GaiaAuthFetcher::IsMultiloginUrl(const GURL& url) { … }
bool GaiaAuthFetcher::IsReAuthApiUrl(const GURL& url) { … }
bool GaiaAuthFetcher::IsListAccountsUrl(const GURL& url) { … }
void GaiaAuthFetcher::CreateAndStartGaiaFetcher(
const std::string& body,
const std::string& body_content_type,
const std::string& headers,
const GURL& gaia_gurl,
network::mojom::CredentialsMode credentials_mode,
const net::NetworkTrafficAnnotationTag& traffic_annotation) { … }
std::string GaiaAuthFetcher::MakeGetTokenPairBody(
const std::string& auth_code,
const std::string& device_id,
const std::string& binding_registration_token) { … }
std::string GaiaAuthFetcher::MakeRevokeTokenBody(
const std::string& auth_token) { … }
void GaiaAuthFetcher::ParseFailureResponse(const std::string& data,
std::string* error,
std::string* error_url) { … }
void GaiaAuthFetcher::StartRevokeOAuth2Token(const std::string& auth_token) { … }
void GaiaAuthFetcher::StartAuthCodeForOAuth2TokenExchange(
const std::string& auth_code,
const std::string& user_agent_full_version_list,
const std::string& binding_registration_token) { … }
void GaiaAuthFetcher::StartAuthCodeForOAuth2TokenExchangeWithDeviceId(
const std::string& auth_code,
const std::string& device_id,
const std::string& user_agent_full_version_list,
const std::string& binding_registration_token) { … }
void GaiaAuthFetcher::StartListAccounts() { … }
void GaiaAuthFetcher::StartOAuthMultilogin(
gaia::MultiloginMode mode,
const std::vector<MultiloginTokenIDPair>& accounts,
const std::string& external_cc_result) { … }
void GaiaAuthFetcher::StartLogOut() { … }
void GaiaAuthFetcher::StartCreateReAuthProofTokenForParent(
const std::string& child_oauth_access_token,
const std::string& parent_obfuscated_gaia_id,
const std::string& parent_credential) { … }
void GaiaAuthFetcher::StartGetCheckConnectionInfo() { … }
GoogleServiceAuthError GaiaAuthFetcher::GenerateAuthError(
const std::string& data,
net::Error net_error) { … }
void GaiaAuthFetcher::OnOAuth2TokenPairFetched(const std::string& data,
net::Error net_error,
int response_code) { … }
void GaiaAuthFetcher::OnOAuth2RevokeTokenFetched(const std::string& data,
net::Error net_error,
int response_code) { … }
void GaiaAuthFetcher::OnListAccountsFetched(const std::string& data,
net::Error net_error,
int response_code) { … }
void GaiaAuthFetcher::OnLogOutFetched(const std::string& data,
net::Error net_error,
int response_code) { … }
void GaiaAuthFetcher::OnReAuthApiInfoFetched(const std::string& data,
net::Error net_error,
int response_code) { … }
void GaiaAuthFetcher::OnGetCheckConnectionInfoFetched(const std::string& data,
net::Error net_error,
int response_code) { … }
void GaiaAuthFetcher::OnOAuthMultiloginFetched(const std::string& data,
net::Error net_error,
int response_code) { … }
void GaiaAuthFetcher::OnURLLoadComplete(
std::unique_ptr<std::string> response_body) { … }
void GaiaAuthFetcher::OnURLLoadCompleteInternal(net::Error net_error,
int response_code,
std::string data) { … }
void GaiaAuthFetcher::DispatchFetchedRequest(const GURL& url,
const std::string& data,
net::Error net_error,
int response_code) { … }