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 <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 oauth2_token_gurl_(GaiaUrls::GetInstance()->oauth2_token_url()), | 176 oauth2_token_gurl_(GaiaUrls::GetInstance()->oauth2_token_url()), |
177 oauth2_revoke_gurl_(GaiaUrls::GetInstance()->oauth2_revoke_url()), | 177 oauth2_revoke_gurl_(GaiaUrls::GetInstance()->oauth2_revoke_url()), |
178 get_user_info_gurl_(GaiaUrls::GetInstance()->get_user_info_url()), | 178 get_user_info_gurl_(GaiaUrls::GetInstance()->get_user_info_url()), |
179 merge_session_gurl_(GaiaUrls::GetInstance()->merge_session_url()), | 179 merge_session_gurl_(GaiaUrls::GetInstance()->merge_session_url()), |
180 uberauth_token_gurl_(GaiaUrls::GetInstance()->oauth1_login_url().Resolve( | 180 uberauth_token_gurl_(GaiaUrls::GetInstance()->oauth1_login_url().Resolve( |
181 base::StringPrintf(kUberAuthTokenURLFormat, source.c_str()))), | 181 base::StringPrintf(kUberAuthTokenURLFormat, source.c_str()))), |
182 oauth_login_gurl_(GaiaUrls::GetInstance()->oauth1_login_url()), | 182 oauth_login_gurl_(GaiaUrls::GetInstance()->oauth1_login_url()), |
183 list_accounts_gurl_(GaiaUrls::GetInstance()->list_accounts_url()), | 183 list_accounts_gurl_(GaiaUrls::GetInstance()->list_accounts_url()), |
184 client_login_to_oauth2_gurl_( | 184 client_login_to_oauth2_gurl_( |
185 GaiaUrls::GetInstance()->client_login_to_oauth2_url()), | 185 GaiaUrls::GetInstance()->client_login_to_oauth2_url()), |
186 fetch_pending_(false), | 186 fetch_pending_(false) {} |
187 fetch_code_only_(false) {} | |
188 | 187 |
189 GaiaAuthFetcher::~GaiaAuthFetcher() {} | 188 GaiaAuthFetcher::~GaiaAuthFetcher() {} |
190 | 189 |
191 bool GaiaAuthFetcher::HasPendingFetch() { | 190 bool GaiaAuthFetcher::HasPendingFetch() { |
192 return fetch_pending_; | 191 return fetch_pending_; |
193 } | 192 } |
194 | 193 |
195 void GaiaAuthFetcher::CancelRequest() { | 194 void GaiaAuthFetcher::CancelRequest() { |
196 fetcher_.reset(); | 195 fetcher_.reset(); |
197 fetch_pending_ = false; | 196 fetch_pending_ = false; |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 fetcher_.reset(CreateGaiaFetcher(getter_, | 536 fetcher_.reset(CreateGaiaFetcher(getter_, |
538 request_body_, | 537 request_body_, |
539 std::string(), | 538 std::string(), |
540 oauth2_revoke_gurl_, | 539 oauth2_revoke_gurl_, |
541 kLoadFlagsIgnoreCookies, | 540 kLoadFlagsIgnoreCookies, |
542 this)); | 541 this)); |
543 fetch_pending_ = true; | 542 fetch_pending_ = true; |
544 fetcher_->Start(); | 543 fetcher_->Start(); |
545 } | 544 } |
546 | 545 |
547 void GaiaAuthFetcher::StartCookieForOAuthCodeExchange( | |
548 const std::string& session_index) { | |
549 // Same as the first step of StartCookieForOAuthLoginTokenExchange; | |
550 StartCookieForOAuthLoginTokenExchange(session_index); | |
551 fetch_code_only_ = true; | |
552 } | |
553 | |
554 void GaiaAuthFetcher::StartCookieForOAuthLoginTokenExchange( | 546 void GaiaAuthFetcher::StartCookieForOAuthLoginTokenExchange( |
555 const std::string& session_index) { | 547 const std::string& session_index) { |
556 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; | 548 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; |
557 | 549 |
558 DVLOG(1) << "Starting OAuth login token fetch with cookie jar"; | 550 DVLOG(1) << "Starting OAuth login token fetch with cookie jar"; |
559 request_body_ = MakeGetAuthCodeBody(); | 551 request_body_ = MakeGetAuthCodeBody(); |
560 | 552 |
561 client_login_to_oauth2_gurl_ = | 553 client_login_to_oauth2_gurl_ = |
562 GaiaUrls::GetInstance()->client_login_to_oauth2_url(); | 554 GaiaUrls::GetInstance()->client_login_to_oauth2_url(); |
563 if (!session_index.empty()) { | 555 if (!session_index.empty()) { |
564 client_login_to_oauth2_gurl_ = | 556 client_login_to_oauth2_gurl_ = |
565 client_login_to_oauth2_gurl_.Resolve("?authuser=" + session_index); | 557 client_login_to_oauth2_gurl_.Resolve("?authuser=" + session_index); |
566 } | 558 } |
567 | 559 |
568 fetcher_.reset(CreateGaiaFetcher(getter_, | 560 fetcher_.reset(CreateGaiaFetcher(getter_, |
569 request_body_, | 561 request_body_, |
570 std::string(), | 562 std::string(), |
571 client_login_to_oauth2_gurl_, | 563 client_login_to_oauth2_gurl_, |
572 net::LOAD_NORMAL, | 564 net::LOAD_NORMAL, |
573 this)); | 565 this)); |
574 fetch_pending_ = true; | 566 fetch_pending_ = true; |
575 fetch_code_only_ = false; | |
576 fetcher_->Start(); | 567 fetcher_->Start(); |
577 } | 568 } |
578 | 569 |
579 void GaiaAuthFetcher::StartAuthCodeForOAuth2TokenExchange( | 570 void GaiaAuthFetcher::StartAuthCodeForOAuth2TokenExchange( |
580 const std::string& auth_code) { | 571 const std::string& auth_code) { |
581 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; | 572 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; |
582 | 573 |
583 DVLOG(1) << "Starting OAuth token pair fetch"; | 574 DVLOG(1) << "Starting OAuth token pair fetch"; |
584 request_body_ = MakeGetTokenPairBody(auth_code); | 575 request_body_ = MakeGetTokenPairBody(auth_code); |
585 fetcher_.reset(CreateGaiaFetcher(getter_, | 576 fetcher_.reset(CreateGaiaFetcher(getter_, |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
757 } | 748 } |
758 | 749 |
759 void GaiaAuthFetcher::OnClientLoginToOAuth2Fetched( | 750 void GaiaAuthFetcher::OnClientLoginToOAuth2Fetched( |
760 const std::string& data, | 751 const std::string& data, |
761 const net::ResponseCookies& cookies, | 752 const net::ResponseCookies& cookies, |
762 const net::URLRequestStatus& status, | 753 const net::URLRequestStatus& status, |
763 int response_code) { | 754 int response_code) { |
764 if (status.is_success() && response_code == net::HTTP_OK) { | 755 if (status.is_success() && response_code == net::HTTP_OK) { |
765 std::string auth_code; | 756 std::string auth_code; |
766 ParseClientLoginToOAuth2Response(cookies, &auth_code); | 757 ParseClientLoginToOAuth2Response(cookies, &auth_code); |
767 if (fetch_code_only_) | 758 StartAuthCodeForOAuth2TokenExchange(auth_code); |
768 consumer_->OnClientOAuthCodeSuccess(auth_code); | |
769 else | |
770 StartAuthCodeForOAuth2TokenExchange(auth_code); | |
771 } else { | 759 } else { |
772 GoogleServiceAuthError auth_error(GenerateAuthError(data, status)); | 760 GoogleServiceAuthError auth_error(GenerateAuthError(data, status)); |
773 if (fetch_code_only_) | 761 consumer_->OnClientOAuthFailure(auth_error); |
774 consumer_->OnClientOAuthCodeFailure(auth_error); | |
775 else | |
776 consumer_->OnClientOAuthFailure(auth_error); | |
777 } | 762 } |
778 } | 763 } |
779 | 764 |
780 void GaiaAuthFetcher::OnOAuth2TokenPairFetched( | 765 void GaiaAuthFetcher::OnOAuth2TokenPairFetched( |
781 const std::string& data, | 766 const std::string& data, |
782 const net::URLRequestStatus& status, | 767 const net::URLRequestStatus& status, |
783 int response_code) { | 768 int response_code) { |
784 std::string refresh_token; | 769 std::string refresh_token; |
785 std::string access_token; | 770 std::string access_token; |
786 int expires_in_secs = 0; | 771 int expires_in_secs = 0; |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
921 NOTREACHED(); | 906 NOTREACHED(); |
922 } | 907 } |
923 } | 908 } |
924 | 909 |
925 // static | 910 // static |
926 bool GaiaAuthFetcher::IsSecondFactorSuccess( | 911 bool GaiaAuthFetcher::IsSecondFactorSuccess( |
927 const std::string& alleged_error) { | 912 const std::string& alleged_error) { |
928 return alleged_error.find(kSecondFactor) != | 913 return alleged_error.find(kSecondFactor) != |
929 std::string::npos; | 914 std::string::npos; |
930 } | 915 } |
OLD | NEW |