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 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) { | 186 fetch_pending_(false), |
187 fetch_token_from_auth_code_(false) { | |
xiyuan
2016/01/27 22:51:29
nit: use the non-static class member initializers
khmel
2016/01/27 23:16:13
Done.
| |
187 } | 188 } |
188 | 189 |
189 GaiaAuthFetcher::~GaiaAuthFetcher() {} | 190 GaiaAuthFetcher::~GaiaAuthFetcher() {} |
190 | 191 |
191 bool GaiaAuthFetcher::HasPendingFetch() { | 192 bool GaiaAuthFetcher::HasPendingFetch() { |
192 return fetch_pending_; | 193 return fetch_pending_; |
193 } | 194 } |
194 | 195 |
195 void GaiaAuthFetcher::SetPendingFetch(bool pending_fetch) { | 196 void GaiaAuthFetcher::SetPendingFetch(bool pending_fetch) { |
196 fetch_pending_ = pending_fetch; | 197 fetch_pending_ = pending_fetch; |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
519 | 520 |
520 void GaiaAuthFetcher::StartCookieForOAuthLoginTokenExchange( | 521 void GaiaAuthFetcher::StartCookieForOAuthLoginTokenExchange( |
521 const std::string& session_index) { | 522 const std::string& session_index) { |
522 StartCookieForOAuthLoginTokenExchangeWithDeviceId(session_index, | 523 StartCookieForOAuthLoginTokenExchangeWithDeviceId(session_index, |
523 std::string()); | 524 std::string()); |
524 } | 525 } |
525 | 526 |
526 void GaiaAuthFetcher::StartCookieForOAuthLoginTokenExchangeWithDeviceId( | 527 void GaiaAuthFetcher::StartCookieForOAuthLoginTokenExchangeWithDeviceId( |
527 const std::string& session_index, | 528 const std::string& session_index, |
528 const std::string& device_id) { | 529 const std::string& device_id) { |
530 StartCookieForOAuthLoginTokenExchangeWithClientIdAndDeviceId( | |
531 true, | |
532 session_index, | |
533 GaiaUrls::GetInstance()->oauth2_chrome_client_id(), | |
534 device_id); | |
535 } | |
536 | |
537 void GaiaAuthFetcher::StartCookieForOAuthLoginTokenExchangeWithClientIdAndDevice Id( | |
xiyuan
2016/01/27 22:51:30
nit: The name is insane. Can we call it StartCooki
khmel
2016/01/27 23:16:13
Agree :)
But I followed style used here. BTW, I tr
xiyuan
2016/01/27 23:19:31
Understand. I would try to follow existing convent
| |
538 bool fetch_token_from_auth_code, | |
539 const std::string& session_index, | |
540 const std::string& client_id, | |
541 const std::string& device_id) { | |
529 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; | 542 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; |
530 | 543 |
531 VLOG(1) << "Starting OAuth login token fetch with cookie jar"; | 544 VLOG(1) << "Starting OAuth login token fetch with cookie jar"; |
532 | 545 |
533 std::string encoded_scope = net::EscapeUrlEncodedData( | 546 std::string encoded_scope = net::EscapeUrlEncodedData( |
534 GaiaConstants::kOAuth1LoginScope, true); | 547 GaiaConstants::kOAuth1LoginScope, true); |
535 std::string encoded_client_id = net::EscapeUrlEncodedData( | 548 std::string encoded_client_id = net::EscapeUrlEncodedData(client_id, true); |
536 GaiaUrls::GetInstance()->oauth2_chrome_client_id(), true); | |
537 std::string query_string = | 549 std::string query_string = |
538 base::StringPrintf(kClientLoginToOAuth2URLFormat, encoded_scope.c_str(), | 550 base::StringPrintf(kClientLoginToOAuth2URLFormat, encoded_scope.c_str(), |
539 encoded_client_id.c_str()); | 551 encoded_client_id.c_str()); |
540 if (!device_id.empty()) | 552 if (!device_id.empty()) |
541 query_string += "&device_type=chrome"; | 553 query_string += "&device_type=chrome"; |
542 if (!session_index.empty()) | 554 if (!session_index.empty()) |
543 query_string += "&authuser=" + session_index; | 555 query_string += "&authuser=" + session_index; |
544 | 556 |
545 std::string device_id_header; | 557 std::string device_id_header; |
546 if (!device_id.empty()) { | 558 if (!device_id.empty()) { |
547 device_id_header = | 559 device_id_header = |
548 base::StringPrintf(kDeviceIdHeaderFormat, device_id.c_str()); | 560 base::StringPrintf(kDeviceIdHeaderFormat, device_id.c_str()); |
549 } | 561 } |
550 | 562 |
563 fetch_token_from_auth_code_ = fetch_token_from_auth_code; | |
551 CreateAndStartGaiaFetcher(std::string(), device_id_header, | 564 CreateAndStartGaiaFetcher(std::string(), device_id_header, |
552 client_login_to_oauth2_gurl_.Resolve(query_string), | 565 client_login_to_oauth2_gurl_.Resolve(query_string), |
553 net::LOAD_NORMAL); | 566 net::LOAD_NORMAL); |
554 } | 567 } |
555 | 568 |
556 void GaiaAuthFetcher::StartAuthCodeForOAuth2TokenExchange( | 569 void GaiaAuthFetcher::StartAuthCodeForOAuth2TokenExchange( |
557 const std::string& auth_code) { | 570 const std::string& auth_code) { |
558 StartAuthCodeForOAuth2TokenExchangeWithDeviceId(auth_code, std::string()); | 571 StartAuthCodeForOAuth2TokenExchangeWithDeviceId(auth_code, std::string()); |
559 } | 572 } |
560 | 573 |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
731 } | 744 } |
732 | 745 |
733 void GaiaAuthFetcher::OnClientLoginToOAuth2Fetched( | 746 void GaiaAuthFetcher::OnClientLoginToOAuth2Fetched( |
734 const std::string& data, | 747 const std::string& data, |
735 const net::ResponseCookies& cookies, | 748 const net::ResponseCookies& cookies, |
736 const net::URLRequestStatus& status, | 749 const net::URLRequestStatus& status, |
737 int response_code) { | 750 int response_code) { |
738 if (status.is_success() && response_code == net::HTTP_OK) { | 751 if (status.is_success() && response_code == net::HTTP_OK) { |
739 std::string auth_code; | 752 std::string auth_code; |
740 if (ParseClientLoginToOAuth2Response(cookies, &auth_code)) { | 753 if (ParseClientLoginToOAuth2Response(cookies, &auth_code)) { |
741 StartAuthCodeForOAuth2TokenExchange(auth_code); | 754 // In case fetch_token_from_auth_code_ is not set OnClientOAuthCode |
755 // callback for consumer_ must be last call in context of this object | |
756 // because consumer may delete GaiaAuthFetcher after getting the final | |
757 // result. | |
758 if (fetch_token_from_auth_code_) { | |
759 consumer_->OnClientOAuthCode(auth_code); | |
xiyuan
2016/01/27 22:51:30
I wonder whether we should call this. The auth cod
khmel
2016/01/27 23:16:13
Yes, this would be better.
| |
760 StartAuthCodeForOAuth2TokenExchange(auth_code); | |
761 } else { | |
762 consumer_->OnClientOAuthCode(auth_code); | |
763 } | |
742 } else { | 764 } else { |
743 GoogleServiceAuthError auth_error( | 765 GoogleServiceAuthError auth_error( |
744 GoogleServiceAuthError::FromUnexpectedServiceResponse( | 766 GoogleServiceAuthError::FromUnexpectedServiceResponse( |
745 "ClientLogin response cookies didn't contain an auth code")); | 767 "ClientLogin response cookies didn't contain an auth code")); |
746 consumer_->OnClientOAuthFailure(auth_error); | 768 consumer_->OnClientOAuthFailure(auth_error); |
747 } | 769 } |
748 } else { | 770 } else { |
749 GoogleServiceAuthError auth_error(GenerateAuthError(data, status)); | 771 GoogleServiceAuthError auth_error(GenerateAuthError(data, status)); |
750 consumer_->OnClientOAuthFailure(auth_error); | 772 consumer_->OnClientOAuthFailure(auth_error); |
751 } | 773 } |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
983 return alleged_error.find(kSecondFactor) != | 1005 return alleged_error.find(kSecondFactor) != |
984 std::string::npos; | 1006 std::string::npos; |
985 } | 1007 } |
986 | 1008 |
987 // static | 1009 // static |
988 bool GaiaAuthFetcher::IsWebLoginRequiredSuccess( | 1010 bool GaiaAuthFetcher::IsWebLoginRequiredSuccess( |
989 const std::string& alleged_error) { | 1011 const std::string& alleged_error) { |
990 return alleged_error.find(kWebLoginRequired) != | 1012 return alleged_error.find(kWebLoginRequired) != |
991 std::string::npos; | 1013 std::string::npos; |
992 } | 1014 } |
OLD | NEW |