Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: google_apis/gaia/gaia_auth_fetcher.cc

Issue 424233002: When the user signs in, make sure to set cookies on all reachable google (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « google_apis/gaia/gaia_auth_fetcher.h ('k') | google_apis/gaia/gaia_auth_fetcher_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 client_login_gurl_(GaiaUrls::GetInstance()->client_login_url()), 179 client_login_gurl_(GaiaUrls::GetInstance()->client_login_url()),
180 issue_auth_token_gurl_(GaiaUrls::GetInstance()->issue_auth_token_url()), 180 issue_auth_token_gurl_(GaiaUrls::GetInstance()->issue_auth_token_url()),
181 oauth2_token_gurl_(GaiaUrls::GetInstance()->oauth2_token_url()), 181 oauth2_token_gurl_(GaiaUrls::GetInstance()->oauth2_token_url()),
182 oauth2_revoke_gurl_(GaiaUrls::GetInstance()->oauth2_revoke_url()), 182 oauth2_revoke_gurl_(GaiaUrls::GetInstance()->oauth2_revoke_url()),
183 get_user_info_gurl_(GaiaUrls::GetInstance()->get_user_info_url()), 183 get_user_info_gurl_(GaiaUrls::GetInstance()->get_user_info_url()),
184 merge_session_gurl_(GaiaUrls::GetInstance()->merge_session_url()), 184 merge_session_gurl_(GaiaUrls::GetInstance()->merge_session_url()),
185 uberauth_token_gurl_(GaiaUrls::GetInstance()->oauth1_login_url().Resolve( 185 uberauth_token_gurl_(GaiaUrls::GetInstance()->oauth1_login_url().Resolve(
186 base::StringPrintf(kUberAuthTokenURLFormat, source.c_str()))), 186 base::StringPrintf(kUberAuthTokenURLFormat, source.c_str()))),
187 oauth_login_gurl_(GaiaUrls::GetInstance()->oauth1_login_url()), 187 oauth_login_gurl_(GaiaUrls::GetInstance()->oauth1_login_url()),
188 list_accounts_gurl_(GaiaUrls::GetInstance()->list_accounts_url()), 188 list_accounts_gurl_(GaiaUrls::GetInstance()->list_accounts_url()),
189 get_check_connection_info_url_(
190 GaiaUrls::GetInstance()->get_check_connection_info_url()),
189 client_login_to_oauth2_gurl_( 191 client_login_to_oauth2_gurl_(
190 GaiaUrls::GetInstance()->client_login_to_oauth2_url()), 192 GaiaUrls::GetInstance()->client_login_to_oauth2_url()),
191 fetch_pending_(false) {} 193 fetch_pending_(false) {}
192 194
193 GaiaAuthFetcher::~GaiaAuthFetcher() {} 195 GaiaAuthFetcher::~GaiaAuthFetcher() {}
194 196
195 bool GaiaAuthFetcher::HasPendingFetch() { 197 bool GaiaAuthFetcher::HasPendingFetch() {
196 return fetch_pending_; 198 return fetch_pending_;
197 } 199 }
198 200
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 344
343 // static 345 // static
344 std::string GaiaAuthFetcher::MakeGetUserInfoBody(const std::string& lsid) { 346 std::string GaiaAuthFetcher::MakeGetUserInfoBody(const std::string& lsid) {
345 std::string encoded_lsid = net::EscapeUrlEncodedData(lsid, true); 347 std::string encoded_lsid = net::EscapeUrlEncodedData(lsid, true);
346 return base::StringPrintf(kGetUserInfoFormat, encoded_lsid.c_str()); 348 return base::StringPrintf(kGetUserInfoFormat, encoded_lsid.c_str());
347 } 349 }
348 350
349 // static 351 // static
350 std::string GaiaAuthFetcher::MakeMergeSessionBody( 352 std::string GaiaAuthFetcher::MakeMergeSessionBody(
351 const std::string& auth_token, 353 const std::string& auth_token,
354 const std::string& external_cc_result,
352 const std::string& continue_url, 355 const std::string& continue_url,
353 const std::string& source) { 356 const std::string& source) {
354 std::string encoded_auth_token = net::EscapeUrlEncodedData(auth_token, true); 357 std::string encoded_auth_token = net::EscapeUrlEncodedData(auth_token, true);
355 std::string encoded_continue_url = net::EscapeUrlEncodedData(continue_url, 358 std::string encoded_continue_url = net::EscapeUrlEncodedData(continue_url,
356 true); 359 true);
357 std::string encoded_source = net::EscapeUrlEncodedData(source, true); 360 std::string encoded_source = net::EscapeUrlEncodedData(source, true);
358 return base::StringPrintf(kMergeSessionFormat, 361 std::string result = base::StringPrintf(kMergeSessionFormat,
359 encoded_auth_token.c_str(), 362 encoded_auth_token.c_str(),
360 encoded_continue_url.c_str(), 363 encoded_continue_url.c_str(),
361 encoded_source.c_str()); 364 encoded_source.c_str());
365 if (!external_cc_result.empty()) {
366 base::StringAppendF(&result, "&externalCcResult=%s",
367 net::EscapeUrlEncodedData(
368 external_cc_result, true).c_str());
369 }
370
371 return result;
362 } 372 }
363 373
364 // static 374 // static
365 std::string GaiaAuthFetcher::MakeGetAuthCodeHeader( 375 std::string GaiaAuthFetcher::MakeGetAuthCodeHeader(
366 const std::string& auth_token) { 376 const std::string& auth_token) {
367 return base::StringPrintf(kAuthHeaderFormat, auth_token.c_str()); 377 return base::StringPrintf(kAuthHeaderFormat, auth_token.c_str());
368 } 378 }
369 379
370 // Helper method that extracts tokens from a successful reply. 380 // Helper method that extracts tokens from a successful reply.
371 // static 381 // static
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 fetcher_.reset(CreateGaiaFetcher(getter_, 625 fetcher_.reset(CreateGaiaFetcher(getter_,
616 request_body_, 626 request_body_,
617 std::string(), 627 std::string(),
618 get_user_info_gurl_, 628 get_user_info_gurl_,
619 kLoadFlagsIgnoreCookies, 629 kLoadFlagsIgnoreCookies,
620 this)); 630 this));
621 fetch_pending_ = true; 631 fetch_pending_ = true;
622 fetcher_->Start(); 632 fetcher_->Start();
623 } 633 }
624 634
625 void GaiaAuthFetcher::StartMergeSession(const std::string& uber_token) { 635 void GaiaAuthFetcher::StartMergeSession(const std::string& uber_token,
636 const std::string& external_cc_result) {
626 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; 637 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!";
627 638
628 DVLOG(1) << "Starting MergeSession with uber_token=" << uber_token; 639 DVLOG(1) << "Starting MergeSession with uber_token=" << uber_token;
629 640
630 // The continue URL is a required parameter of the MergeSession API, but in 641 // The continue URL is a required parameter of the MergeSession API, but in
631 // this case we don't actually need or want to navigate to it. Setting it to 642 // this case we don't actually need or want to navigate to it. Setting it to
632 // an arbitrary Google URL. 643 // an arbitrary Google URL.
633 // 644 //
634 // In order for the new session to be merged correctly, the server needs to 645 // In order for the new session to be merged correctly, the server needs to
635 // know what sessions already exist in the browser. The fetcher needs to be 646 // know what sessions already exist in the browser. The fetcher needs to be
636 // created such that it sends the cookies with the request, which is 647 // created such that it sends the cookies with the request, which is
637 // different from all other requests the fetcher can make. 648 // different from all other requests the fetcher can make.
638 std::string continue_url("http://www.google.com"); 649 std::string continue_url("http://www.google.com");
639 request_body_ = MakeMergeSessionBody(uber_token, continue_url, source_); 650 request_body_ = MakeMergeSessionBody(uber_token, external_cc_result,
651 continue_url, source_);
640 fetcher_.reset(CreateGaiaFetcher(getter_, 652 fetcher_.reset(CreateGaiaFetcher(getter_,
641 request_body_, 653 request_body_,
642 std::string(), 654 std::string(),
643 merge_session_gurl_, 655 merge_session_gurl_,
644 net::LOAD_NORMAL, 656 net::LOAD_NORMAL,
645 this)); 657 this));
646 fetch_pending_ = true; 658 fetch_pending_ = true;
647 fetcher_->Start(); 659 fetcher_->Start();
648 } 660 }
649 661
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 fetcher_.reset(CreateGaiaFetcher(getter_, 700 fetcher_.reset(CreateGaiaFetcher(getter_,
689 " ", // To force an HTTP POST. 701 " ", // To force an HTTP POST.
690 "Origin: https://www.google.com", 702 "Origin: https://www.google.com",
691 list_accounts_gurl_, 703 list_accounts_gurl_,
692 net::LOAD_NORMAL, 704 net::LOAD_NORMAL,
693 this)); 705 this));
694 fetch_pending_ = true; 706 fetch_pending_ = true;
695 fetcher_->Start(); 707 fetcher_->Start();
696 } 708 }
697 709
710 void GaiaAuthFetcher::StartGetCheckConnectionInfo() {
711 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!";
712
713 fetcher_.reset(CreateGaiaFetcher(getter_,
714 std::string(),
715 std::string(),
716 get_check_connection_info_url_,
717 kLoadFlagsIgnoreCookies,
718 this));
719 fetch_pending_ = true;
720 fetcher_->Start();
721 }
722
698 // static 723 // static
699 GoogleServiceAuthError GaiaAuthFetcher::GenerateAuthError( 724 GoogleServiceAuthError GaiaAuthFetcher::GenerateAuthError(
700 const std::string& data, 725 const std::string& data,
701 const net::URLRequestStatus& status) { 726 const net::URLRequestStatus& status) {
702 if (!status.is_success()) { 727 if (!status.is_success()) {
703 if (status.status() == net::URLRequestStatus::CANCELED) { 728 if (status.status() == net::URLRequestStatus::CANCELED) {
704 return GoogleServiceAuthError(GoogleServiceAuthError::REQUEST_CANCELED); 729 return GoogleServiceAuthError(GoogleServiceAuthError::REQUEST_CANCELED);
705 } 730 }
706 DLOG(WARNING) << "Could not reach Google Accounts servers: errno " 731 DLOG(WARNING) << "Could not reach Google Accounts servers: errno "
707 << status.error(); 732 << status.error();
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
884 std::string lsid; 909 std::string lsid;
885 std::string token; 910 std::string token;
886 ParseClientLoginResponse(data, &sid, &lsid, &token); 911 ParseClientLoginResponse(data, &sid, &lsid, &token);
887 consumer_->OnClientLoginSuccess( 912 consumer_->OnClientLoginSuccess(
888 GaiaAuthConsumer::ClientLoginResult(sid, lsid, token, data)); 913 GaiaAuthConsumer::ClientLoginResult(sid, lsid, token, data));
889 } else { 914 } else {
890 consumer_->OnClientLoginFailure(GenerateAuthError(data, status)); 915 consumer_->OnClientLoginFailure(GenerateAuthError(data, status));
891 } 916 }
892 } 917 }
893 918
919 void GaiaAuthFetcher::OnGetCheckConnectionInfoFetched(
920 const std::string& data,
921 const net::URLRequestStatus& status,
922 int response_code) {
923 if (status.is_success() && response_code == net::HTTP_OK) {
924 consumer_->OnGetCheckConnectionInfoSuccess(data);
925 } else {
926 consumer_->OnGetCheckConnectionInfoError(GenerateAuthError(data, status));
927 }
928 }
929
894 void GaiaAuthFetcher::OnURLFetchComplete(const net::URLFetcher* source) { 930 void GaiaAuthFetcher::OnURLFetchComplete(const net::URLFetcher* source) {
895 fetch_pending_ = false; 931 fetch_pending_ = false;
896 // Some of the GAIA requests perform redirects, which results in the final 932 // Some of the GAIA requests perform redirects, which results in the final
897 // URL of the fetcher not being the original URL requested. Therefore use 933 // URL of the fetcher not being the original URL requested. Therefore use
898 // the original URL when determining which OnXXX function to call. 934 // the original URL when determining which OnXXX function to call.
899 const GURL& url = source->GetOriginalURL(); 935 const GURL& url = source->GetOriginalURL();
900 const net::URLRequestStatus& status = source->GetStatus(); 936 const net::URLRequestStatus& status = source->GetStatus();
901 int response_code = source->GetResponseCode(); 937 int response_code = source->GetResponseCode();
902 std::string data; 938 std::string data;
903 source->GetResponseAsString(&data); 939 source->GetResponseAsString(&data);
(...skipping 21 matching lines...) Expand all
925 } else if (url == merge_session_gurl_) { 961 } else if (url == merge_session_gurl_) {
926 OnMergeSessionFetched(data, status, response_code); 962 OnMergeSessionFetched(data, status, response_code);
927 } else if (url == uberauth_token_gurl_) { 963 } else if (url == uberauth_token_gurl_) {
928 OnUberAuthTokenFetch(data, status, response_code); 964 OnUberAuthTokenFetch(data, status, response_code);
929 } else if (url == oauth_login_gurl_) { 965 } else if (url == oauth_login_gurl_) {
930 OnOAuthLoginFetched(data, status, response_code); 966 OnOAuthLoginFetched(data, status, response_code);
931 } else if (url == oauth2_revoke_gurl_) { 967 } else if (url == oauth2_revoke_gurl_) {
932 OnOAuth2RevokeTokenFetched(data, status, response_code); 968 OnOAuth2RevokeTokenFetched(data, status, response_code);
933 } else if (url == list_accounts_gurl_) { 969 } else if (url == list_accounts_gurl_) {
934 OnListAccountsFetched(data, status, response_code); 970 OnListAccountsFetched(data, status, response_code);
971 } else if (url == get_check_connection_info_url_) {
972 OnGetCheckConnectionInfoFetched(data, status, response_code);
935 } else { 973 } else {
936 NOTREACHED(); 974 NOTREACHED();
937 } 975 }
938 } 976 }
939 977
940 // static 978 // static
941 bool GaiaAuthFetcher::IsSecondFactorSuccess( 979 bool GaiaAuthFetcher::IsSecondFactorSuccess(
942 const std::string& alleged_error) { 980 const std::string& alleged_error) {
943 return alleged_error.find(kSecondFactor) != 981 return alleged_error.find(kSecondFactor) !=
944 std::string::npos; 982 std::string::npos;
945 } 983 }
OLDNEW
« no previous file with comments | « google_apis/gaia/gaia_auth_fetcher.h ('k') | google_apis/gaia/gaia_auth_fetcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698