Chromium Code Reviews| 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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 const char GaiaAuthFetcher::kClientLoginToOAuth2WithDeviceTypeBodyFormat[] = | 108 const char GaiaAuthFetcher::kClientLoginToOAuth2WithDeviceTypeBodyFormat[] = |
| 109 "scope=%s&client_id=%s&device_type=chrome"; | 109 "scope=%s&client_id=%s&device_type=chrome"; |
| 110 // static | 110 // static |
| 111 const char GaiaAuthFetcher::kOAuth2CodeToTokenPairBodyFormat[] = | 111 const char GaiaAuthFetcher::kOAuth2CodeToTokenPairBodyFormat[] = |
| 112 "scope=%s&" | 112 "scope=%s&" |
| 113 "grant_type=authorization_code&" | 113 "grant_type=authorization_code&" |
| 114 "client_id=%s&" | 114 "client_id=%s&" |
| 115 "client_secret=%s&" | 115 "client_secret=%s&" |
| 116 "code=%s"; | 116 "code=%s"; |
| 117 // static | 117 // static |
| 118 const char GaiaAuthFetcher::kOAuth2CodeToTokenPairDeviceIdParam[] = | |
| 119 "device_id=%s&device_type=chrome"; | |
| 120 // static | |
| 118 const char GaiaAuthFetcher::kOAuth2RevokeTokenBodyFormat[] = | 121 const char GaiaAuthFetcher::kOAuth2RevokeTokenBodyFormat[] = |
| 119 "token=%s"; | 122 "token=%s"; |
| 120 // static | 123 // static |
| 121 const char GaiaAuthFetcher::kGetUserInfoFormat[] = | 124 const char GaiaAuthFetcher::kGetUserInfoFormat[] = |
| 122 "LSID=%s"; | 125 "LSID=%s"; |
| 123 // static | 126 // static |
| 124 const char GaiaAuthFetcher::kMergeSessionFormat[] = | 127 const char GaiaAuthFetcher::kMergeSessionFormat[] = |
| 125 "uberauth=%s&" | 128 "uberauth=%s&" |
| 126 "continue=%s&" | 129 "continue=%s&" |
| 127 "source=%s"; | 130 "source=%s"; |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 334 encoded_client_id.c_str()); | 337 encoded_client_id.c_str()); |
| 335 } else { | 338 } else { |
| 336 return base::StringPrintf(kClientLoginToOAuth2BodyFormat, | 339 return base::StringPrintf(kClientLoginToOAuth2BodyFormat, |
| 337 encoded_scope.c_str(), | 340 encoded_scope.c_str(), |
| 338 encoded_client_id.c_str()); | 341 encoded_client_id.c_str()); |
| 339 } | 342 } |
| 340 } | 343 } |
| 341 | 344 |
| 342 // static | 345 // static |
| 343 std::string GaiaAuthFetcher::MakeGetTokenPairBody( | 346 std::string GaiaAuthFetcher::MakeGetTokenPairBody( |
| 344 const std::string& auth_code) { | 347 const std::string& auth_code, |
| 348 const std::string& device_id) { | |
| 345 std::string encoded_scope = net::EscapeUrlEncodedData( | 349 std::string encoded_scope = net::EscapeUrlEncodedData( |
| 346 GaiaConstants::kOAuth1LoginScope, true); | 350 GaiaConstants::kOAuth1LoginScope, true); |
| 347 std::string encoded_client_id = net::EscapeUrlEncodedData( | 351 std::string encoded_client_id = net::EscapeUrlEncodedData( |
| 348 GaiaUrls::GetInstance()->oauth2_chrome_client_id(), true); | 352 GaiaUrls::GetInstance()->oauth2_chrome_client_id(), true); |
| 349 std::string encoded_client_secret = net::EscapeUrlEncodedData( | 353 std::string encoded_client_secret = net::EscapeUrlEncodedData( |
| 350 GaiaUrls::GetInstance()->oauth2_chrome_client_secret(), true); | 354 GaiaUrls::GetInstance()->oauth2_chrome_client_secret(), true); |
| 351 std::string encoded_auth_code = net::EscapeUrlEncodedData(auth_code, true); | 355 std::string encoded_auth_code = net::EscapeUrlEncodedData(auth_code, true); |
| 352 return base::StringPrintf(kOAuth2CodeToTokenPairBodyFormat, | 356 std::string body = base::StringPrintf( |
| 353 encoded_scope.c_str(), | 357 kOAuth2CodeToTokenPairBodyFormat, encoded_scope.c_str(), |
| 354 encoded_client_id.c_str(), | 358 encoded_client_id.c_str(), encoded_client_secret.c_str(), |
| 355 encoded_client_secret.c_str(), | 359 encoded_auth_code.c_str()); |
| 356 encoded_auth_code.c_str()); | 360 if (!device_id.empty()) |
|
achuithb
2015/05/12 23:25:01
nit: Believe you need {} here?
dzhioev (left Google)
2015/05/13 00:25:18
Done.
| |
| 361 body += "&" + base::StringPrintf(kOAuth2CodeToTokenPairDeviceIdParam, | |
| 362 device_id.c_str()); | |
| 363 return body; | |
| 357 } | 364 } |
| 358 | 365 |
| 359 // static | 366 // static |
| 360 std::string GaiaAuthFetcher::MakeRevokeTokenBody( | 367 std::string GaiaAuthFetcher::MakeRevokeTokenBody( |
| 361 const std::string& auth_token) { | 368 const std::string& auth_token) { |
| 362 return base::StringPrintf(kOAuth2RevokeTokenBodyFormat, auth_token.c_str()); | 369 return base::StringPrintf(kOAuth2RevokeTokenBodyFormat, auth_token.c_str()); |
| 363 } | 370 } |
| 364 | 371 |
| 365 // static | 372 // static |
| 366 std::string GaiaAuthFetcher::MakeGetUserInfoBody(const std::string& lsid) { | 373 std::string GaiaAuthFetcher::MakeGetUserInfoBody(const std::string& lsid) { |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 671 | 678 |
| 672 fetcher_ = | 679 fetcher_ = |
| 673 CreateGaiaFetcher(getter_, request_body_, device_id_header, | 680 CreateGaiaFetcher(getter_, request_body_, device_id_header, |
| 674 client_login_to_oauth2_gurl_, net::LOAD_NORMAL, this); | 681 client_login_to_oauth2_gurl_, net::LOAD_NORMAL, this); |
| 675 fetch_pending_ = true; | 682 fetch_pending_ = true; |
| 676 fetcher_->Start(); | 683 fetcher_->Start(); |
| 677 } | 684 } |
| 678 | 685 |
| 679 void GaiaAuthFetcher::StartAuthCodeForOAuth2TokenExchange( | 686 void GaiaAuthFetcher::StartAuthCodeForOAuth2TokenExchange( |
| 680 const std::string& auth_code) { | 687 const std::string& auth_code) { |
| 688 StartAuthCodeForOAuth2TokenExchangeWithDeviceId(auth_code, std::string()); | |
| 689 } | |
| 690 | |
| 691 void GaiaAuthFetcher::StartAuthCodeForOAuth2TokenExchangeWithDeviceId( | |
| 692 const std::string& auth_code, | |
| 693 const std::string& device_id) { | |
| 681 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; | 694 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; |
| 682 | 695 |
| 683 DVLOG(1) << "Starting OAuth token pair fetch"; | 696 DVLOG(1) << "Starting OAuth token pair fetch"; |
| 684 request_body_ = MakeGetTokenPairBody(auth_code); | 697 request_body_ = MakeGetTokenPairBody(auth_code, device_id); |
| 685 fetcher_ = | 698 fetcher_ = |
| 686 CreateGaiaFetcher(getter_, request_body_, std::string(), | 699 CreateGaiaFetcher(getter_, request_body_, std::string(), |
| 687 oauth2_token_gurl_, kLoadFlagsIgnoreCookies, this); | 700 oauth2_token_gurl_, kLoadFlagsIgnoreCookies, this); |
| 688 fetch_pending_ = true; | 701 fetch_pending_ = true; |
| 689 fetcher_->Start(); | 702 fetcher_->Start(); |
| 690 } | 703 } |
| 691 | 704 |
| 692 void GaiaAuthFetcher::StartGetUserInfo(const std::string& lsid) { | 705 void GaiaAuthFetcher::StartGetUserInfo(const std::string& lsid) { |
| 693 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; | 706 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; |
| 694 | 707 |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1106 return alleged_error.find(kSecondFactor) != | 1119 return alleged_error.find(kSecondFactor) != |
| 1107 std::string::npos; | 1120 std::string::npos; |
| 1108 } | 1121 } |
| 1109 | 1122 |
| 1110 // static | 1123 // static |
| 1111 bool GaiaAuthFetcher::IsWebLoginRequiredSuccess( | 1124 bool GaiaAuthFetcher::IsWebLoginRequiredSuccess( |
| 1112 const std::string& alleged_error) { | 1125 const std::string& alleged_error) { |
| 1113 return alleged_error.find(kWebLoginRequired) != | 1126 return alleged_error.find(kWebLoginRequired) != |
| 1114 std::string::npos; | 1127 std::string::npos; |
| 1115 } | 1128 } |
| OLD | NEW |