| 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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 uberauth_token_gurl_(GaiaUrls::GetInstance()->oauth1_login_url().Resolve( | 175 uberauth_token_gurl_(GaiaUrls::GetInstance()->oauth1_login_url().Resolve( |
| 176 base::StringPrintf(kUberAuthTokenURLFormat, source.c_str()))), | 176 base::StringPrintf(kUberAuthTokenURLFormat, source.c_str()))), |
| 177 oauth_login_gurl_(GaiaUrls::GetInstance()->oauth1_login_url()), | 177 oauth_login_gurl_(GaiaUrls::GetInstance()->oauth1_login_url()), |
| 178 list_accounts_gurl_( | 178 list_accounts_gurl_( |
| 179 GaiaUrls::GetInstance()->ListAccountsURLWithSource(source)), | 179 GaiaUrls::GetInstance()->ListAccountsURLWithSource(source)), |
| 180 logout_gurl_(GaiaUrls::GetInstance()->LogOutURLWithSource(source)), | 180 logout_gurl_(GaiaUrls::GetInstance()->LogOutURLWithSource(source)), |
| 181 get_check_connection_info_url_( | 181 get_check_connection_info_url_( |
| 182 GaiaUrls::GetInstance()->GetCheckConnectionInfoURLWithSource(source)), | 182 GaiaUrls::GetInstance()->GetCheckConnectionInfoURLWithSource(source)), |
| 183 oauth2_iframe_url_(GaiaUrls::GetInstance()->oauth2_iframe_url()), | 183 oauth2_iframe_url_(GaiaUrls::GetInstance()->oauth2_iframe_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) { | |
| 187 } | 186 } |
| 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::SetPendingFetch(bool pending_fetch) { | 194 void GaiaAuthFetcher::SetPendingFetch(bool pending_fetch) { |
| 196 fetch_pending_ = pending_fetch; | 195 fetch_pending_ = pending_fetch; |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 | 518 |
| 520 void GaiaAuthFetcher::StartCookieForOAuthLoginTokenExchange( | 519 void GaiaAuthFetcher::StartCookieForOAuthLoginTokenExchange( |
| 521 const std::string& session_index) { | 520 const std::string& session_index) { |
| 522 StartCookieForOAuthLoginTokenExchangeWithDeviceId(session_index, | 521 StartCookieForOAuthLoginTokenExchangeWithDeviceId(session_index, |
| 523 std::string()); | 522 std::string()); |
| 524 } | 523 } |
| 525 | 524 |
| 526 void GaiaAuthFetcher::StartCookieForOAuthLoginTokenExchangeWithDeviceId( | 525 void GaiaAuthFetcher::StartCookieForOAuthLoginTokenExchangeWithDeviceId( |
| 527 const std::string& session_index, | 526 const std::string& session_index, |
| 528 const std::string& device_id) { | 527 const std::string& device_id) { |
| 528 StartCookieForOAuthLoginTokenExchange( |
| 529 true, |
| 530 session_index, |
| 531 GaiaUrls::GetInstance()->oauth2_chrome_client_id(), |
| 532 device_id); |
| 533 } |
| 534 |
| 535 void GaiaAuthFetcher::StartCookieForOAuthLoginTokenExchange( |
| 536 bool fetch_token_from_auth_code, |
| 537 const std::string& session_index, |
| 538 const std::string& client_id, |
| 539 const std::string& device_id) { |
| 529 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; | 540 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; |
| 530 | 541 |
| 531 VLOG(1) << "Starting OAuth login token fetch with cookie jar"; | 542 VLOG(1) << "Starting OAuth login token fetch with cookie jar"; |
| 532 | 543 |
| 533 std::string encoded_scope = net::EscapeUrlEncodedData( | 544 std::string encoded_scope = net::EscapeUrlEncodedData( |
| 534 GaiaConstants::kOAuth1LoginScope, true); | 545 GaiaConstants::kOAuth1LoginScope, true); |
| 535 std::string encoded_client_id = net::EscapeUrlEncodedData( | 546 std::string encoded_client_id = net::EscapeUrlEncodedData(client_id, true); |
| 536 GaiaUrls::GetInstance()->oauth2_chrome_client_id(), true); | |
| 537 std::string query_string = | 547 std::string query_string = |
| 538 base::StringPrintf(kClientLoginToOAuth2URLFormat, encoded_scope.c_str(), | 548 base::StringPrintf(kClientLoginToOAuth2URLFormat, encoded_scope.c_str(), |
| 539 encoded_client_id.c_str()); | 549 encoded_client_id.c_str()); |
| 540 if (!device_id.empty()) | 550 if (!device_id.empty()) |
| 541 query_string += "&device_type=chrome"; | 551 query_string += "&device_type=chrome"; |
| 542 if (!session_index.empty()) | 552 if (!session_index.empty()) |
| 543 query_string += "&authuser=" + session_index; | 553 query_string += "&authuser=" + session_index; |
| 544 | 554 |
| 545 std::string device_id_header; | 555 std::string device_id_header; |
| 546 if (!device_id.empty()) { | 556 if (!device_id.empty()) { |
| 547 device_id_header = | 557 device_id_header = |
| 548 base::StringPrintf(kDeviceIdHeaderFormat, device_id.c_str()); | 558 base::StringPrintf(kDeviceIdHeaderFormat, device_id.c_str()); |
| 549 } | 559 } |
| 550 | 560 |
| 561 fetch_token_from_auth_code_ = fetch_token_from_auth_code; |
| 551 CreateAndStartGaiaFetcher(std::string(), device_id_header, | 562 CreateAndStartGaiaFetcher(std::string(), device_id_header, |
| 552 client_login_to_oauth2_gurl_.Resolve(query_string), | 563 client_login_to_oauth2_gurl_.Resolve(query_string), |
| 553 net::LOAD_NORMAL); | 564 net::LOAD_NORMAL); |
| 554 } | 565 } |
| 555 | 566 |
| 556 void GaiaAuthFetcher::StartAuthCodeForOAuth2TokenExchange( | 567 void GaiaAuthFetcher::StartAuthCodeForOAuth2TokenExchange( |
| 557 const std::string& auth_code) { | 568 const std::string& auth_code) { |
| 558 StartAuthCodeForOAuth2TokenExchangeWithDeviceId(auth_code, std::string()); | 569 StartAuthCodeForOAuth2TokenExchangeWithDeviceId(auth_code, std::string()); |
| 559 } | 570 } |
| 560 | 571 |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 731 } | 742 } |
| 732 | 743 |
| 733 void GaiaAuthFetcher::OnClientLoginToOAuth2Fetched( | 744 void GaiaAuthFetcher::OnClientLoginToOAuth2Fetched( |
| 734 const std::string& data, | 745 const std::string& data, |
| 735 const net::ResponseCookies& cookies, | 746 const net::ResponseCookies& cookies, |
| 736 const net::URLRequestStatus& status, | 747 const net::URLRequestStatus& status, |
| 737 int response_code) { | 748 int response_code) { |
| 738 if (status.is_success() && response_code == net::HTTP_OK) { | 749 if (status.is_success() && response_code == net::HTTP_OK) { |
| 739 std::string auth_code; | 750 std::string auth_code; |
| 740 if (ParseClientLoginToOAuth2Response(cookies, &auth_code)) { | 751 if (ParseClientLoginToOAuth2Response(cookies, &auth_code)) { |
| 741 StartAuthCodeForOAuth2TokenExchange(auth_code); | 752 if (fetch_token_from_auth_code_) |
| 753 StartAuthCodeForOAuth2TokenExchange(auth_code); |
| 754 else |
| 755 consumer_->OnClientOAuthCode(auth_code); |
| 742 } else { | 756 } else { |
| 743 GoogleServiceAuthError auth_error( | 757 GoogleServiceAuthError auth_error( |
| 744 GoogleServiceAuthError::FromUnexpectedServiceResponse( | 758 GoogleServiceAuthError::FromUnexpectedServiceResponse( |
| 745 "ClientLogin response cookies didn't contain an auth code")); | 759 "ClientLogin response cookies didn't contain an auth code")); |
| 746 consumer_->OnClientOAuthFailure(auth_error); | 760 consumer_->OnClientOAuthFailure(auth_error); |
| 747 } | 761 } |
| 748 } else { | 762 } else { |
| 749 GoogleServiceAuthError auth_error(GenerateAuthError(data, status)); | 763 GoogleServiceAuthError auth_error(GenerateAuthError(data, status)); |
| 750 consumer_->OnClientOAuthFailure(auth_error); | 764 consumer_->OnClientOAuthFailure(auth_error); |
| 751 } | 765 } |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 983 return alleged_error.find(kSecondFactor) != | 997 return alleged_error.find(kSecondFactor) != |
| 984 std::string::npos; | 998 std::string::npos; |
| 985 } | 999 } |
| 986 | 1000 |
| 987 // static | 1001 // static |
| 988 bool GaiaAuthFetcher::IsWebLoginRequiredSuccess( | 1002 bool GaiaAuthFetcher::IsWebLoginRequiredSuccess( |
| 989 const std::string& alleged_error) { | 1003 const std::string& alleged_error) { |
| 990 return alleged_error.find(kWebLoginRequired) != | 1004 return alleged_error.find(kWebLoginRequired) != |
| 991 std::string::npos; | 1005 std::string::npos; |
| 992 } | 1006 } |
| OLD | NEW |