| Index: google_apis/gaia/gaia_auth_fetcher.cc
|
| diff --git a/google_apis/gaia/gaia_auth_fetcher.cc b/google_apis/gaia/gaia_auth_fetcher.cc
|
| index 803ad6f936a9384a887e9f6abf1110fde34c6215..04e1a266156c94ce2f3219f326c5856fea85e8ca 100644
|
| --- a/google_apis/gaia/gaia_auth_fetcher.cc
|
| +++ b/google_apis/gaia/gaia_auth_fetcher.cc
|
| @@ -80,6 +80,10 @@ const char GaiaAuthFetcher::kIssueAuthTokenFormat[] =
|
| "service=%s&"
|
| "Session=%s";
|
| // static
|
| +const char GaiaAuthFetcher::kIssueAuthTokenFormatForOAuth2[] =
|
| + "service=%s&"
|
| + "Session=%s";
|
| +// static
|
| const char GaiaAuthFetcher::kClientLoginToOAuth2BodyFormat[] =
|
| "scope=%s&client_id=%s";
|
| // static
|
| @@ -156,6 +160,9 @@ const char GaiaAuthFetcher::kAuthHeaderFormat[] =
|
| // static
|
| const char GaiaAuthFetcher::kOAuthHeaderFormat[] = "Authorization: OAuth %s";
|
| // static
|
| +const char GaiaAuthFetcher::kOAuth2BearerHeaderFormat[] =
|
| + "Authorization: Bearer %s";
|
| +// static
|
| const char GaiaAuthFetcher::kClientLoginToOAuth2CookiePartSecure[] = "Secure";
|
| // static
|
| const char GaiaAuthFetcher::kClientLoginToOAuth2CookiePartHttpOnly[] =
|
| @@ -291,6 +298,19 @@ std::string GaiaAuthFetcher::MakeIssueAuthTokenBody(
|
| }
|
|
|
| // static
|
| +std::string GaiaAuthFetcher::MakeIssueAuthTokenBodyForOAuth2(
|
| + const char* const service) {
|
| + // All tokens should be session tokens except the gaia auth token.
|
| + bool session = true;
|
| + if (!strcmp(service, GaiaConstants::kGaiaService))
|
| + session = false;
|
| +
|
| + return base::StringPrintf(kIssueAuthTokenFormatForOAuth2,
|
| + service,
|
| + session ? "true" : "false");
|
| +}
|
| +
|
| +// static
|
| std::string GaiaAuthFetcher::MakeGetAuthCodeBody() {
|
| std::string encoded_scope = net::EscapeUrlEncodedData(
|
| GaiaUrls::GetInstance()->oauth1_login_scope(), true);
|
| @@ -616,6 +636,27 @@ void GaiaAuthFetcher::StartIssueAuthToken(const std::string& sid,
|
| fetcher_->Start();
|
| }
|
|
|
| +void GaiaAuthFetcher::StartIssueAuthTokenForOAuth2(
|
| + const std::string& oauth2_access_token,
|
| + const char* const service) {
|
| + DCHECK(!fetch_pending_) << "Tried to fetch two things at once!";
|
| +
|
| + DVLOG(1) << "Starting IssueAuthToken for: " << service;
|
| + requested_service_ = service;
|
| + request_body_ = MakeIssueAuthTokenBodyForOAuth2(service);
|
| + std::string authentication_header =
|
| + base::StringPrintf(kOAuth2BearerHeaderFormat,
|
| + oauth2_access_token.c_str());
|
| + fetcher_.reset(CreateGaiaFetcher(getter_,
|
| + request_body_,
|
| + authentication_header,
|
| + issue_auth_token_gurl_,
|
| + kLoadFlagsIgnoreCookies,
|
| + this));
|
| + fetch_pending_ = true;
|
| + fetcher_->Start();
|
| +}
|
| +
|
| void GaiaAuthFetcher::StartLsoForOAuthLoginTokenExchange(
|
| const std::string& auth_token) {
|
| DCHECK(!fetch_pending_) << "Tried to fetch two things at once!";
|
| @@ -770,7 +811,7 @@ void GaiaAuthFetcher::StartOAuthLogin(const std::string& access_token,
|
|
|
| request_body_ = MakeOAuthLoginBody(service, source_);
|
| std::string authentication_header =
|
| - base::StringPrintf("Authorization: Bearer %s", access_token.c_str());
|
| + base::StringPrintf(kOAuth2BearerHeaderFormat, access_token.c_str());
|
| fetcher_.reset(CreateGaiaFetcher(getter_,
|
| request_body_,
|
| authentication_header,
|
|
|