| 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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 source_(source), | 175 source_(source), |
| 176 client_login_gurl_(GaiaUrls::GetInstance()->client_login_url()), | 176 client_login_gurl_(GaiaUrls::GetInstance()->client_login_url()), |
| 177 issue_auth_token_gurl_(GaiaUrls::GetInstance()->issue_auth_token_url()), | 177 issue_auth_token_gurl_(GaiaUrls::GetInstance()->issue_auth_token_url()), |
| 178 oauth2_token_gurl_(GaiaUrls::GetInstance()->oauth2_token_url()), | 178 oauth2_token_gurl_(GaiaUrls::GetInstance()->oauth2_token_url()), |
| 179 oauth2_revoke_gurl_(GaiaUrls::GetInstance()->oauth2_revoke_url()), | 179 oauth2_revoke_gurl_(GaiaUrls::GetInstance()->oauth2_revoke_url()), |
| 180 get_user_info_gurl_(GaiaUrls::GetInstance()->get_user_info_url()), | 180 get_user_info_gurl_(GaiaUrls::GetInstance()->get_user_info_url()), |
| 181 merge_session_gurl_(GaiaUrls::GetInstance()->merge_session_url()), | 181 merge_session_gurl_(GaiaUrls::GetInstance()->merge_session_url()), |
| 182 uberauth_token_gurl_(GaiaUrls::GetInstance()->oauth1_login_url().Resolve( | 182 uberauth_token_gurl_(GaiaUrls::GetInstance()->oauth1_login_url().Resolve( |
| 183 base::StringPrintf(kUberAuthTokenURLFormat, source.c_str()))), | 183 base::StringPrintf(kUberAuthTokenURLFormat, source.c_str()))), |
| 184 oauth_login_gurl_(GaiaUrls::GetInstance()->oauth1_login_url()), | 184 oauth_login_gurl_(GaiaUrls::GetInstance()->oauth1_login_url()), |
| 185 list_accounts_gurl_(GaiaUrls::GetInstance()->list_accounts_url()), |
| 185 client_login_to_oauth2_gurl_( | 186 client_login_to_oauth2_gurl_( |
| 186 GaiaUrls::GetInstance()->client_login_to_oauth2_url()), | 187 GaiaUrls::GetInstance()->client_login_to_oauth2_url()), |
| 187 fetch_pending_(false) {} | 188 fetch_pending_(false) {} |
| 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 |
| (...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 fetcher_.reset(CreateGaiaFetcher(getter_, | 653 fetcher_.reset(CreateGaiaFetcher(getter_, |
| 653 request_body_, | 654 request_body_, |
| 654 authentication_header, | 655 authentication_header, |
| 655 oauth_login_gurl_, | 656 oauth_login_gurl_, |
| 656 kLoadFlagsIgnoreCookies, | 657 kLoadFlagsIgnoreCookies, |
| 657 this)); | 658 this)); |
| 658 fetch_pending_ = true; | 659 fetch_pending_ = true; |
| 659 fetcher_->Start(); | 660 fetcher_->Start(); |
| 660 } | 661 } |
| 661 | 662 |
| 663 void GaiaAuthFetcher::StartListAccounts() { |
| 664 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; |
| 665 |
| 666 fetcher_.reset(CreateGaiaFetcher(getter_, |
| 667 " ", // To force an HTTP POST. |
| 668 "Origin: https://www.google.com", |
| 669 list_accounts_gurl_, |
| 670 net::LOAD_NORMAL, |
| 671 this)); |
| 672 fetch_pending_ = true; |
| 673 fetcher_->Start(); |
| 674 } |
| 675 |
| 662 // static | 676 // static |
| 663 GoogleServiceAuthError GaiaAuthFetcher::GenerateAuthError( | 677 GoogleServiceAuthError GaiaAuthFetcher::GenerateAuthError( |
| 664 const std::string& data, | 678 const std::string& data, |
| 665 const net::URLRequestStatus& status) { | 679 const net::URLRequestStatus& status) { |
| 666 if (!status.is_success()) { | 680 if (!status.is_success()) { |
| 667 if (status.status() == net::URLRequestStatus::CANCELED) { | 681 if (status.status() == net::URLRequestStatus::CANCELED) { |
| 668 return GoogleServiceAuthError(GoogleServiceAuthError::REQUEST_CANCELED); | 682 return GoogleServiceAuthError(GoogleServiceAuthError::REQUEST_CANCELED); |
| 669 } else { | 683 } else { |
| 670 DLOG(WARNING) << "Could not reach Google Accounts servers: errno " | 684 DLOG(WARNING) << "Could not reach Google Accounts servers: errno " |
| 671 << status.error(); | 685 << status.error(); |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 837 } | 851 } |
| 838 } | 852 } |
| 839 | 853 |
| 840 void GaiaAuthFetcher::OnOAuth2RevokeTokenFetched( | 854 void GaiaAuthFetcher::OnOAuth2RevokeTokenFetched( |
| 841 const std::string& data, | 855 const std::string& data, |
| 842 const net::URLRequestStatus& status, | 856 const net::URLRequestStatus& status, |
| 843 int response_code) { | 857 int response_code) { |
| 844 consumer_->OnOAuth2RevokeTokenCompleted(); | 858 consumer_->OnOAuth2RevokeTokenCompleted(); |
| 845 } | 859 } |
| 846 | 860 |
| 861 void GaiaAuthFetcher::OnListAccountsFetched(const std::string& data, |
| 862 const net::URLRequestStatus& status, |
| 863 int response_code) { |
| 864 if (status.is_success() && response_code == net::HTTP_OK) { |
| 865 consumer_->OnListAccountsSuccess(data); |
| 866 } else { |
| 867 consumer_->OnListAccountsFailure(GenerateAuthError(data, status)); |
| 868 } |
| 869 } |
| 870 |
| 847 void GaiaAuthFetcher::OnGetUserInfoFetched( | 871 void GaiaAuthFetcher::OnGetUserInfoFetched( |
| 848 const std::string& data, | 872 const std::string& data, |
| 849 const net::URLRequestStatus& status, | 873 const net::URLRequestStatus& status, |
| 850 int response_code) { | 874 int response_code) { |
| 851 if (status.is_success() && response_code == net::HTTP_OK) { | 875 if (status.is_success() && response_code == net::HTTP_OK) { |
| 852 std::vector<std::pair<std::string, std::string> > tokens; | 876 std::vector<std::pair<std::string, std::string> > tokens; |
| 853 UserInfoMap matches; | 877 UserInfoMap matches; |
| 854 base::SplitStringIntoKeyValuePairs(data, '=', '\n', &tokens); | 878 base::SplitStringIntoKeyValuePairs(data, '=', '\n', &tokens); |
| 855 std::vector<std::pair<std::string, std::string> >::iterator i; | 879 std::vector<std::pair<std::string, std::string> >::iterator i; |
| 856 for (i = tokens.begin(); i != tokens.end(); ++i) { | 880 for (i = tokens.begin(); i != tokens.end(); ++i) { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 930 } else if (url == get_user_info_gurl_) { | 954 } else if (url == get_user_info_gurl_) { |
| 931 OnGetUserInfoFetched(data, status, response_code); | 955 OnGetUserInfoFetched(data, status, response_code); |
| 932 } else if (url == merge_session_gurl_) { | 956 } else if (url == merge_session_gurl_) { |
| 933 OnMergeSessionFetched(data, status, response_code); | 957 OnMergeSessionFetched(data, status, response_code); |
| 934 } else if (url == uberauth_token_gurl_) { | 958 } else if (url == uberauth_token_gurl_) { |
| 935 OnUberAuthTokenFetch(data, status, response_code); | 959 OnUberAuthTokenFetch(data, status, response_code); |
| 936 } else if (url == oauth_login_gurl_) { | 960 } else if (url == oauth_login_gurl_) { |
| 937 OnOAuthLoginFetched(data, status, response_code); | 961 OnOAuthLoginFetched(data, status, response_code); |
| 938 } else if (url == oauth2_revoke_gurl_) { | 962 } else if (url == oauth2_revoke_gurl_) { |
| 939 OnOAuth2RevokeTokenFetched(data, status, response_code); | 963 OnOAuth2RevokeTokenFetched(data, status, response_code); |
| 964 } else if (url == list_accounts_gurl_) { |
| 965 OnListAccountsFetched(data, status, response_code); |
| 940 } else { | 966 } else { |
| 941 NOTREACHED(); | 967 NOTREACHED(); |
| 942 } | 968 } |
| 943 } | 969 } |
| 944 | 970 |
| 945 // static | 971 // static |
| 946 bool GaiaAuthFetcher::IsSecondFactorSuccess( | 972 bool GaiaAuthFetcher::IsSecondFactorSuccess( |
| 947 const std::string& alleged_error) { | 973 const std::string& alleged_error) { |
| 948 return alleged_error.find(kSecondFactor) != | 974 return alleged_error.find(kSecondFactor) != |
| 949 std::string::npos; | 975 std::string::npos; |
| 950 } | 976 } |
| OLD | NEW |