#include "google_apis/gaia/oauth2_access_token_fetcher_impl.h"
#include <string>
#include <vector>
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/json/json_reader.h"
#include "base/strings/escape.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/time/time.h"
#include "base/values.h"
#include "build/chromeos_buildflags.h"
#include "google_apis/credentials_mode.h"
#include "google_apis/gaia/gaia_auth_util.h"
#include "google_apis/gaia/google_service_auth_error.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 {
constexpr char kGetAccessTokenBodyFormat[] = …;
constexpr char kGetAccessTokenBodyWithScopeFormat[] = …;
constexpr char kGrantTypeAuthCode[] = …;
constexpr char kGrantTypeRefreshToken[] = …;
constexpr char kKeyAuthCode[] = …;
constexpr char kKeyRefreshToken[] = …;
constexpr char kAccessTokenKey[] = …;
constexpr char krefreshTokenKey[] = …;
constexpr char kExpiresInKey[] = …;
constexpr char kIdTokenKey[] = …;
constexpr char kErrorKey[] = …;
constexpr char kErrorSubTypeKey[] = …;
constexpr char kErrorDescriptionKey[] = …;
#if BUILDFLAG(IS_CHROMEOS_ASH)
constexpr char kRaptRequiredError[] = "rapt_required";
constexpr char kInvalidRaptError[] = "invalid_rapt";
#endif
OAuth2AccessTokenFetcherImpl::OAuth2Response
OAuth2ResponseErrorToOAuth2Response(const std::string& error) { … }
static std::unique_ptr<network::SimpleURLLoader> CreateURLLoader(
const GURL& url,
const std::string& body,
const net::NetworkTrafficAnnotationTag& traffic_annotation) { … }
GoogleServiceAuthError CreateErrorForInvalidGrant(
const std::string& error_subtype,
const std::string& error_description) { … }
}
OAuth2AccessTokenFetcherImpl::OAuth2AccessTokenFetcherImpl(
OAuth2AccessTokenConsumer* consumer,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const std::string& refresh_token,
const std::string& auth_code)
: … { … }
OAuth2AccessTokenFetcherImpl::~OAuth2AccessTokenFetcherImpl() = default;
void OAuth2AccessTokenFetcherImpl::CancelRequest() { … }
void OAuth2AccessTokenFetcherImpl::Start(
const std::string& client_id,
const std::string& client_secret,
const std::vector<std::string>& scopes) { … }
void OAuth2AccessTokenFetcherImpl::StartGetAccessToken() { … }
void OAuth2AccessTokenFetcherImpl::EndGetAccessToken(
std::unique_ptr<std::string> response_body) { … }
void OAuth2AccessTokenFetcherImpl::OnGetTokenSuccess(
const OAuth2AccessTokenConsumer::TokenResponse& token_response) { … }
void OAuth2AccessTokenFetcherImpl::OnGetTokenFailure(
const GoogleServiceAuthError& error) { … }
void OAuth2AccessTokenFetcherImpl::OnURLLoadComplete(
std::unique_ptr<std::string> response_body) { … }
std::string OAuth2AccessTokenFetcherImpl::MakeGetAccessTokenBody(
const std::string& client_id,
const std::string& client_secret,
const std::string& refresh_token,
const std::string& auth_code,
const std::vector<std::string>& scopes) { … }
bool OAuth2AccessTokenFetcherImpl::ParseGetAccessTokenSuccessResponse(
const std::string& response_body,
OAuth2AccessTokenConsumer::TokenResponse* token_response) { … }
bool OAuth2AccessTokenFetcherImpl::ParseGetAccessTokenFailureResponse(
const std::string& response_body,
std::string* error,
std::string* error_subtype,
std::string* error_description) { … }