OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "google_apis/gaia/gaia_auth_fetcher.h" | 5 #include "google_apis/gaia/gaia_auth_fetcher.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 to_return->SetRequestContext(getter); | 212 to_return->SetRequestContext(getter); |
213 to_return->SetUploadData("application/x-www-form-urlencoded", body); | 213 to_return->SetUploadData("application/x-www-form-urlencoded", body); |
214 | 214 |
215 DVLOG(2) << "Gaia fetcher URL: " << gaia_gurl.spec(); | 215 DVLOG(2) << "Gaia fetcher URL: " << gaia_gurl.spec(); |
216 DVLOG(2) << "Gaia fetcher headers: " << headers; | 216 DVLOG(2) << "Gaia fetcher headers: " << headers; |
217 DVLOG(2) << "Gaia fetcher body: " << body; | 217 DVLOG(2) << "Gaia fetcher body: " << body; |
218 | 218 |
219 // The Gaia token exchange requests do not require any cookie-based | 219 // The Gaia token exchange requests do not require any cookie-based |
220 // identification as part of requests. We suppress sending any cookies to | 220 // identification as part of requests. We suppress sending any cookies to |
221 // maintain a separation between the user's browsing and Chrome's internal | 221 // maintain a separation between the user's browsing and Chrome's internal |
222 // services. Where such mixing is desired (MergeSession), it will be done | 222 // services. Where such mixing is desired (MergeSession or OAuthLogin), it |
223 // explicitly. | 223 // will be done explicitly. |
224 to_return->SetLoadFlags(load_flags); | 224 to_return->SetLoadFlags(load_flags); |
225 | 225 |
226 // Fetchers are sometimes cancelled because a network change was detected, | 226 // Fetchers are sometimes cancelled because a network change was detected, |
227 // especially at startup and after sign-in on ChromeOS. Retrying once should | 227 // especially at startup and after sign-in on ChromeOS. Retrying once should |
228 // be enough in those cases; let the fetcher retry up to 3 times just in case. | 228 // be enough in those cases; let the fetcher retry up to 3 times just in case. |
229 // http://crbug.com/163710 | 229 // http://crbug.com/163710 |
230 to_return->SetAutomaticallyRetryOnNetworkChanges(3); | 230 to_return->SetAutomaticallyRetryOnNetworkChanges(3); |
231 | 231 |
232 if (!headers.empty()) | 232 if (!headers.empty()) |
233 to_return->SetExtraRequestHeaders(headers); | 233 to_return->SetExtraRequestHeaders(headers); |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; | 629 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; |
630 | 630 |
631 DVLOG(1) << "Starting StartTokenFetchForUberAuthExchange with access_token=" | 631 DVLOG(1) << "Starting StartTokenFetchForUberAuthExchange with access_token=" |
632 << access_token; | 632 << access_token; |
633 std::string authentication_header = | 633 std::string authentication_header = |
634 base::StringPrintf(kOAuthHeaderFormat, access_token.c_str()); | 634 base::StringPrintf(kOAuthHeaderFormat, access_token.c_str()); |
635 fetcher_.reset(CreateGaiaFetcher(getter_, | 635 fetcher_.reset(CreateGaiaFetcher(getter_, |
636 std::string(), | 636 std::string(), |
637 authentication_header, | 637 authentication_header, |
638 uberauth_token_gurl_, | 638 uberauth_token_gurl_, |
639 kLoadFlagsIgnoreCookies, | 639 net::LOAD_NORMAL, |
640 this)); | 640 this)); |
641 fetch_pending_ = true; | 641 fetch_pending_ = true; |
642 fetcher_->Start(); | 642 fetcher_->Start(); |
643 } | 643 } |
644 | 644 |
645 void GaiaAuthFetcher::StartOAuthLogin(const std::string& access_token, | 645 void GaiaAuthFetcher::StartOAuthLogin(const std::string& access_token, |
646 const std::string& service) { | 646 const std::string& service) { |
647 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; | 647 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; |
648 | 648 |
649 request_body_ = MakeOAuthLoginBody(service, source_); | 649 request_body_ = MakeOAuthLoginBody(service, source_); |
650 std::string authentication_header = | 650 std::string authentication_header = |
651 base::StringPrintf(kOAuth2BearerHeaderFormat, access_token.c_str()); | 651 base::StringPrintf(kOAuth2BearerHeaderFormat, access_token.c_str()); |
652 fetcher_.reset(CreateGaiaFetcher(getter_, | 652 fetcher_.reset(CreateGaiaFetcher(getter_, |
653 request_body_, | 653 request_body_, |
654 authentication_header, | 654 authentication_header, |
655 oauth_login_gurl_, | 655 oauth_login_gurl_, |
656 kLoadFlagsIgnoreCookies, | 656 net::LOAD_NORMAL, |
657 this)); | 657 this)); |
658 fetch_pending_ = true; | 658 fetch_pending_ = true; |
659 fetcher_->Start(); | 659 fetcher_->Start(); |
660 } | 660 } |
661 | 661 |
662 // static | 662 // static |
663 GoogleServiceAuthError GaiaAuthFetcher::GenerateAuthError( | 663 GoogleServiceAuthError GaiaAuthFetcher::GenerateAuthError( |
664 const std::string& data, | 664 const std::string& data, |
665 const net::URLRequestStatus& status) { | 665 const net::URLRequestStatus& status) { |
666 if (!status.is_success()) { | 666 if (!status.is_success()) { |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
941 NOTREACHED(); | 941 NOTREACHED(); |
942 } | 942 } |
943 } | 943 } |
944 | 944 |
945 // static | 945 // static |
946 bool GaiaAuthFetcher::IsSecondFactorSuccess( | 946 bool GaiaAuthFetcher::IsSecondFactorSuccess( |
947 const std::string& alleged_error) { | 947 const std::string& alleged_error) { |
948 return alleged_error.find(kSecondFactor) != | 948 return alleged_error.find(kSecondFactor) != |
949 std::string::npos; | 949 std::string::npos; |
950 } | 950 } |
OLD | NEW |