| 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 "chrome/common/net/gaia/gaia_auth_fetcher.h" | 5 #include "chrome/common/net/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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 const char GaiaAuthFetcher::kOAuth2ExpiresInKey[] = "expires_in"; | 151 const char GaiaAuthFetcher::kOAuth2ExpiresInKey[] = "expires_in"; |
| 152 | 152 |
| 153 GaiaAuthFetcher::GaiaAuthFetcher(GaiaAuthConsumer* consumer, | 153 GaiaAuthFetcher::GaiaAuthFetcher(GaiaAuthConsumer* consumer, |
| 154 const std::string& source, | 154 const std::string& source, |
| 155 net::URLRequestContextGetter* getter) | 155 net::URLRequestContextGetter* getter) |
| 156 : consumer_(consumer), | 156 : consumer_(consumer), |
| 157 getter_(getter), | 157 getter_(getter), |
| 158 source_(source), | 158 source_(source), |
| 159 client_login_gurl_(GaiaUrls::GetInstance()->client_login_url()), | 159 client_login_gurl_(GaiaUrls::GetInstance()->client_login_url()), |
| 160 issue_auth_token_gurl_(GaiaUrls::GetInstance()->issue_auth_token_url()), | 160 issue_auth_token_gurl_(GaiaUrls::GetInstance()->issue_auth_token_url()), |
| 161 client_login_to_oauth2_gurl_( | |
| 162 GaiaUrls::GetInstance()->client_login_to_oauth2_url()), | |
| 163 oauth2_token_gurl_(GaiaUrls::GetInstance()->oauth2_token_url()), | 161 oauth2_token_gurl_(GaiaUrls::GetInstance()->oauth2_token_url()), |
| 164 get_user_info_gurl_(GaiaUrls::GetInstance()->get_user_info_url()), | 162 get_user_info_gurl_(GaiaUrls::GetInstance()->get_user_info_url()), |
| 165 token_auth_gurl_(GaiaUrls::GetInstance()->token_auth_url()), | 163 token_auth_gurl_(GaiaUrls::GetInstance()->token_auth_url()), |
| 166 merge_session_gurl_(GaiaUrls::GetInstance()->merge_session_url()), | 164 merge_session_gurl_(GaiaUrls::GetInstance()->merge_session_url()), |
| 167 uberauth_token_gurl_(base::StringPrintf(kUberAuthTokenURLFormat, | 165 uberauth_token_gurl_(base::StringPrintf(kUberAuthTokenURLFormat, |
| 168 GaiaUrls::GetInstance()->oauth1_login_url().c_str(), source.c_str())), | 166 GaiaUrls::GetInstance()->oauth1_login_url().c_str(), source.c_str())), |
| 167 client_login_to_oauth2_gurl_( |
| 168 GaiaUrls::GetInstance()->client_login_to_oauth2_url()), |
| 169 fetch_pending_(false) {} | 169 fetch_pending_(false) {} |
| 170 | 170 |
| 171 GaiaAuthFetcher::~GaiaAuthFetcher() {} | 171 GaiaAuthFetcher::~GaiaAuthFetcher() {} |
| 172 | 172 |
| 173 bool GaiaAuthFetcher::HasPendingFetch() { | 173 bool GaiaAuthFetcher::HasPendingFetch() { |
| 174 return fetch_pending_; | 174 return fetch_pending_; |
| 175 } | 175 } |
| 176 | 176 |
| 177 void GaiaAuthFetcher::CancelRequest() { | 177 void GaiaAuthFetcher::CancelRequest() { |
| 178 fetcher_.reset(); | 178 fetcher_.reset(); |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 kLoadFlagsIgnoreCookies, | 500 kLoadFlagsIgnoreCookies, |
| 501 this)); | 501 this)); |
| 502 fetch_pending_ = true; | 502 fetch_pending_ = true; |
| 503 fetcher_->Start(); | 503 fetcher_->Start(); |
| 504 } | 504 } |
| 505 | 505 |
| 506 void GaiaAuthFetcher::StartOAuthLoginTokenFetch( | 506 void GaiaAuthFetcher::StartOAuthLoginTokenFetch( |
| 507 const std::string& auth_token) { | 507 const std::string& auth_token) { |
| 508 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; | 508 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; |
| 509 | 509 |
| 510 DVLOG(1) << "Starting OAuth login token fetch"; | 510 DVLOG(1) << "Starting OAuth login token fetch with auth_token"; |
| 511 request_body_ = MakeGetAuthCodeBody(); | 511 request_body_ = MakeGetAuthCodeBody(); |
| 512 | 512 client_login_to_oauth2_gurl_ = |
| 513 // If no auth_token is given, then make sure to use the cookie jar with this | 513 GURL(GaiaUrls::GetInstance()->client_login_to_oauth2_url()); |
| 514 // request. Otherwise the token contains all the necessary information and | |
| 515 // the cookie jar should not be touched. | |
| 516 int load_flags = net::LOAD_NORMAL; | |
| 517 std::string auth_code_header = ""; | |
| 518 | |
| 519 if (!auth_token.empty()) { | |
| 520 load_flags = kLoadFlagsIgnoreCookies; | |
| 521 auth_code_header = MakeGetAuthCodeHeader(auth_token); | |
| 522 } | |
| 523 | 514 |
| 524 fetcher_.reset(CreateGaiaFetcher(getter_, | 515 fetcher_.reset(CreateGaiaFetcher(getter_, |
| 525 request_body_, | 516 request_body_, |
| 526 auth_code_header, | 517 MakeGetAuthCodeHeader(auth_token), |
| 527 client_login_to_oauth2_gurl_, | 518 client_login_to_oauth2_gurl_, |
| 528 load_flags, | 519 kLoadFlagsIgnoreCookies, |
| 529 this)); | 520 this)); |
| 530 fetch_pending_ = true; | 521 fetch_pending_ = true; |
| 531 fetcher_->Start(); | 522 fetcher_->Start(); |
| 523 } |
| 524 |
| 525 void GaiaAuthFetcher::StartOAuthLoginTokenFetchWithCookies( |
| 526 const std::string& session_index) { |
| 527 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; |
| 528 |
| 529 DVLOG(1) << "Starting OAuth login token fetch with cookie jar"; |
| 530 request_body_ = MakeGetAuthCodeBody(); |
| 531 |
| 532 std::string url = GaiaUrls::GetInstance()->client_login_to_oauth2_url(); |
| 533 if (!session_index.empty()) |
| 534 url += "?authuser=" + session_index; |
| 535 |
| 536 client_login_to_oauth2_gurl_ = GURL(url); |
| 537 |
| 538 fetcher_.reset(CreateGaiaFetcher(getter_, |
| 539 request_body_, |
| 540 "", |
| 541 client_login_to_oauth2_gurl_, |
| 542 net::LOAD_NORMAL, |
| 543 this)); |
| 544 fetch_pending_ = true; |
| 545 fetcher_->Start(); |
| 532 } | 546 } |
| 533 | 547 |
| 534 void GaiaAuthFetcher::StartGetUserInfo(const std::string& lsid) { | 548 void GaiaAuthFetcher::StartGetUserInfo(const std::string& lsid) { |
| 535 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; | 549 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; |
| 536 | 550 |
| 537 DVLOG(1) << "Starting GetUserInfo for lsid=" << lsid; | 551 DVLOG(1) << "Starting GetUserInfo for lsid=" << lsid; |
| 538 request_body_ = MakeGetUserInfoBody(lsid); | 552 request_body_ = MakeGetUserInfoBody(lsid); |
| 539 fetcher_.reset(CreateGaiaFetcher(getter_, | 553 fetcher_.reset(CreateGaiaFetcher(getter_, |
| 540 request_body_, | 554 request_body_, |
| 541 "", | 555 "", |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 NOTREACHED(); | 886 NOTREACHED(); |
| 873 } | 887 } |
| 874 } | 888 } |
| 875 | 889 |
| 876 // static | 890 // static |
| 877 bool GaiaAuthFetcher::IsSecondFactorSuccess( | 891 bool GaiaAuthFetcher::IsSecondFactorSuccess( |
| 878 const std::string& alleged_error) { | 892 const std::string& alleged_error) { |
| 879 return alleged_error.find(kSecondFactor) != | 893 return alleged_error.find(kSecondFactor) != |
| 880 std::string::npos; | 894 std::string::npos; |
| 881 } | 895 } |
| OLD | NEW |