| 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 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 fetcher_.reset(CreateGaiaFetcher(getter_, | 668 fetcher_.reset(CreateGaiaFetcher(getter_, |
| 669 request_body_, | 669 request_body_, |
| 670 "", | 670 "", |
| 671 client_login_to_oauth2_gurl_, | 671 client_login_to_oauth2_gurl_, |
| 672 net::LOAD_NORMAL, | 672 net::LOAD_NORMAL, |
| 673 this)); | 673 this)); |
| 674 fetch_pending_ = true; | 674 fetch_pending_ = true; |
| 675 fetcher_->Start(); | 675 fetcher_->Start(); |
| 676 } | 676 } |
| 677 | 677 |
| 678 void GaiaAuthFetcher::StartAuthCodeForOAuth2TokenExchange( |
| 679 const std::string& auth_code) { |
| 680 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; |
| 681 |
| 682 DVLOG(1) << "Starting OAuth token pair fetch"; |
| 683 request_body_ = MakeGetTokenPairBody(auth_code); |
| 684 fetcher_.reset(CreateGaiaFetcher(getter_, |
| 685 request_body_, |
| 686 "", |
| 687 oauth2_token_gurl_, |
| 688 kLoadFlagsIgnoreCookies, |
| 689 this)); |
| 690 fetch_pending_ = true; |
| 691 fetcher_->Start(); |
| 692 } |
| 693 |
| 678 void GaiaAuthFetcher::StartGetUserInfo(const std::string& lsid) { | 694 void GaiaAuthFetcher::StartGetUserInfo(const std::string& lsid) { |
| 679 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; | 695 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; |
| 680 | 696 |
| 681 DVLOG(1) << "Starting GetUserInfo for lsid=" << lsid; | 697 DVLOG(1) << "Starting GetUserInfo for lsid=" << lsid; |
| 682 request_body_ = MakeGetUserInfoBody(lsid); | 698 request_body_ = MakeGetUserInfoBody(lsid); |
| 683 fetcher_.reset(CreateGaiaFetcher(getter_, | 699 fetcher_.reset(CreateGaiaFetcher(getter_, |
| 684 request_body_, | 700 request_body_, |
| 685 "", | 701 "", |
| 686 get_user_info_gurl_, | 702 get_user_info_gurl_, |
| 687 kLoadFlagsIgnoreCookies, | 703 kLoadFlagsIgnoreCookies, |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 935 } | 951 } |
| 936 | 952 |
| 937 void GaiaAuthFetcher::OnClientLoginToOAuth2Fetched( | 953 void GaiaAuthFetcher::OnClientLoginToOAuth2Fetched( |
| 938 const std::string& data, | 954 const std::string& data, |
| 939 const net::ResponseCookies& cookies, | 955 const net::ResponseCookies& cookies, |
| 940 const net::URLRequestStatus& status, | 956 const net::URLRequestStatus& status, |
| 941 int response_code) { | 957 int response_code) { |
| 942 if (status.is_success() && response_code == net::HTTP_OK) { | 958 if (status.is_success() && response_code == net::HTTP_OK) { |
| 943 std::string auth_code; | 959 std::string auth_code; |
| 944 ParseClientLoginToOAuth2Response(cookies, &auth_code); | 960 ParseClientLoginToOAuth2Response(cookies, &auth_code); |
| 945 StartOAuth2TokenPairFetch(auth_code); | 961 StartAuthCodeForOAuth2TokenExchange(auth_code); |
| 946 } else { | 962 } else { |
| 947 consumer_->OnClientOAuthFailure(GenerateAuthError(data, status)); | 963 consumer_->OnClientOAuthFailure(GenerateAuthError(data, status)); |
| 948 } | 964 } |
| 949 } | 965 } |
| 950 | 966 |
| 951 void GaiaAuthFetcher::StartOAuth2TokenPairFetch(const std::string& auth_code) { | |
| 952 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; | |
| 953 | |
| 954 DVLOG(1) << "Starting OAuth token pair fetch"; | |
| 955 request_body_ = MakeGetTokenPairBody(auth_code); | |
| 956 fetcher_.reset(CreateGaiaFetcher(getter_, | |
| 957 request_body_, | |
| 958 "", | |
| 959 oauth2_token_gurl_, | |
| 960 kLoadFlagsIgnoreCookies, | |
| 961 this)); | |
| 962 fetch_pending_ = true; | |
| 963 fetcher_->Start(); | |
| 964 } | |
| 965 | |
| 966 void GaiaAuthFetcher::OnOAuth2TokenPairFetched( | 967 void GaiaAuthFetcher::OnOAuth2TokenPairFetched( |
| 967 const std::string& data, | 968 const std::string& data, |
| 968 const net::URLRequestStatus& status, | 969 const net::URLRequestStatus& status, |
| 969 int response_code) { | 970 int response_code) { |
| 970 std::string refresh_token; | 971 std::string refresh_token; |
| 971 std::string access_token; | 972 std::string access_token; |
| 972 int expires_in_secs = 0; | 973 int expires_in_secs = 0; |
| 973 | 974 |
| 974 bool success = false; | 975 bool success = false; |
| 975 if (status.is_success() && response_code == net::HTTP_OK) { | 976 if (status.is_success() && response_code == net::HTTP_OK) { |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1122 NOTREACHED(); | 1123 NOTREACHED(); |
| 1123 } | 1124 } |
| 1124 } | 1125 } |
| 1125 | 1126 |
| 1126 // static | 1127 // static |
| 1127 bool GaiaAuthFetcher::IsSecondFactorSuccess( | 1128 bool GaiaAuthFetcher::IsSecondFactorSuccess( |
| 1128 const std::string& alleged_error) { | 1129 const std::string& alleged_error) { |
| 1129 return alleged_error.find(kSecondFactor) != | 1130 return alleged_error.find(kSecondFactor) != |
| 1130 std::string::npos; | 1131 std::string::npos; |
| 1131 } | 1132 } |
| OLD | NEW |