| 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 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 service, | 299 service, |
| 300 session ? "true" : "false"); | 300 session ? "true" : "false"); |
| 301 } | 301 } |
| 302 | 302 |
| 303 // static | 303 // static |
| 304 std::string GaiaAuthFetcher::MakeGetAuthCodeBody() { | 304 std::string GaiaAuthFetcher::MakeGetAuthCodeBody() { |
| 305 std::string encoded_scope = net::EscapeUrlEncodedData( | 305 std::string encoded_scope = net::EscapeUrlEncodedData( |
| 306 GaiaUrls::GetInstance()->oauth1_login_scope(), true); | 306 GaiaUrls::GetInstance()->oauth1_login_scope(), true); |
| 307 std::string encoded_client_id = net::EscapeUrlEncodedData( | 307 std::string encoded_client_id = net::EscapeUrlEncodedData( |
| 308 GaiaUrls::GetInstance()->oauth2_chrome_client_id(), true); | 308 GaiaUrls::GetInstance()->oauth2_chrome_client_id(), true); |
| 309 return StringPrintf(kClientLoginToOAuth2BodyFormat, | 309 return base::StringPrintf(kClientLoginToOAuth2BodyFormat, |
| 310 encoded_scope.c_str(), | 310 encoded_scope.c_str(), |
| 311 encoded_client_id.c_str()); | 311 encoded_client_id.c_str()); |
| 312 } | 312 } |
| 313 | 313 |
| 314 // static | 314 // static |
| 315 std::string GaiaAuthFetcher::MakeGetTokenPairBody( | 315 std::string GaiaAuthFetcher::MakeGetTokenPairBody( |
| 316 const std::string& auth_code) { | 316 const std::string& auth_code) { |
| 317 std::string encoded_scope = net::EscapeUrlEncodedData( | 317 std::string encoded_scope = net::EscapeUrlEncodedData( |
| 318 GaiaUrls::GetInstance()->oauth1_login_scope(), true); | 318 GaiaUrls::GetInstance()->oauth1_login_scope(), true); |
| 319 std::string encoded_client_id = net::EscapeUrlEncodedData( | 319 std::string encoded_client_id = net::EscapeUrlEncodedData( |
| 320 GaiaUrls::GetInstance()->oauth2_chrome_client_id(), true); | 320 GaiaUrls::GetInstance()->oauth2_chrome_client_id(), true); |
| 321 std::string encoded_client_secret = net::EscapeUrlEncodedData( | 321 std::string encoded_client_secret = net::EscapeUrlEncodedData( |
| 322 GaiaUrls::GetInstance()->oauth2_chrome_client_secret(), true); | 322 GaiaUrls::GetInstance()->oauth2_chrome_client_secret(), true); |
| 323 std::string encoded_auth_code = net::EscapeUrlEncodedData(auth_code, true); | 323 std::string encoded_auth_code = net::EscapeUrlEncodedData(auth_code, true); |
| 324 return StringPrintf(kOAuth2CodeToTokenPairBodyFormat, | 324 return base::StringPrintf(kOAuth2CodeToTokenPairBodyFormat, |
| 325 encoded_scope.c_str(), | 325 encoded_scope.c_str(), |
| 326 encoded_client_id.c_str(), | 326 encoded_client_id.c_str(), |
| 327 encoded_client_secret.c_str(), | 327 encoded_client_secret.c_str(), |
| 328 encoded_auth_code.c_str()); | 328 encoded_auth_code.c_str()); |
| 329 } | 329 } |
| 330 | 330 |
| 331 // static | 331 // static |
| 332 std::string GaiaAuthFetcher::MakeGetUserInfoBody(const std::string& lsid) { | 332 std::string GaiaAuthFetcher::MakeGetUserInfoBody(const std::string& lsid) { |
| 333 std::string encoded_lsid = net::EscapeUrlEncodedData(lsid, true); | 333 std::string encoded_lsid = net::EscapeUrlEncodedData(lsid, true); |
| 334 return base::StringPrintf(kGetUserInfoFormat, encoded_lsid.c_str()); | 334 return base::StringPrintf(kGetUserInfoFormat, encoded_lsid.c_str()); |
| 335 } | 335 } |
| 336 | 336 |
| 337 // static | 337 // static |
| 338 std::string GaiaAuthFetcher::MakeMergeSessionBody( | 338 std::string GaiaAuthFetcher::MakeMergeSessionBody( |
| 339 const std::string& auth_token, | 339 const std::string& auth_token, |
| 340 const std::string& continue_url, | 340 const std::string& continue_url, |
| 341 const std::string& source) { | 341 const std::string& source) { |
| 342 std::string encoded_auth_token = net::EscapeUrlEncodedData(auth_token, true); | 342 std::string encoded_auth_token = net::EscapeUrlEncodedData(auth_token, true); |
| 343 std::string encoded_continue_url = net::EscapeUrlEncodedData(continue_url, | 343 std::string encoded_continue_url = net::EscapeUrlEncodedData(continue_url, |
| 344 true); | 344 true); |
| 345 std::string encoded_source = net::EscapeUrlEncodedData(source, true); | 345 std::string encoded_source = net::EscapeUrlEncodedData(source, true); |
| 346 return base::StringPrintf(kMergeSessionFormat, | 346 return base::StringPrintf(kMergeSessionFormat, |
| 347 encoded_auth_token.c_str(), | 347 encoded_auth_token.c_str(), |
| 348 encoded_continue_url.c_str(), | 348 encoded_continue_url.c_str(), |
| 349 encoded_source.c_str()); | 349 encoded_source.c_str()); |
| 350 } | 350 } |
| 351 | 351 |
| 352 // static | 352 // static |
| 353 std::string GaiaAuthFetcher::MakeGetAuthCodeHeader( | 353 std::string GaiaAuthFetcher::MakeGetAuthCodeHeader( |
| 354 const std::string& auth_token) { | 354 const std::string& auth_token) { |
| 355 return StringPrintf(kAuthHeaderFormat, auth_token.c_str()); | 355 return base::StringPrintf(kAuthHeaderFormat, auth_token.c_str()); |
| 356 } | 356 } |
| 357 | 357 |
| 358 // Helper method that extracts tokens from a successful reply. | 358 // Helper method that extracts tokens from a successful reply. |
| 359 // static | 359 // static |
| 360 void GaiaAuthFetcher::ParseClientLoginResponse(const std::string& data, | 360 void GaiaAuthFetcher::ParseClientLoginResponse(const std::string& data, |
| 361 std::string* sid, | 361 std::string* sid, |
| 362 std::string* lsid, | 362 std::string* lsid, |
| 363 std::string* token) { | 363 std::string* token) { |
| 364 using std::vector; | 364 using std::vector; |
| 365 using std::pair; | 365 using std::pair; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 std::string json_string; | 443 std::string json_string; |
| 444 base::JSONWriter::Write(dict.get(), &json_string); | 444 base::JSONWriter::Write(dict.get(), &json_string); |
| 445 return json_string; | 445 return json_string; |
| 446 } | 446 } |
| 447 | 447 |
| 448 // static | 448 // static |
| 449 std::string GaiaAuthFetcher::MakeOAuthLoginBody(const std::string& service, | 449 std::string GaiaAuthFetcher::MakeOAuthLoginBody(const std::string& service, |
| 450 const std::string& source) { | 450 const std::string& source) { |
| 451 std::string encoded_service = net::EscapeUrlEncodedData(service, true); | 451 std::string encoded_service = net::EscapeUrlEncodedData(service, true); |
| 452 std::string encoded_source = net::EscapeUrlEncodedData(source, true); | 452 std::string encoded_source = net::EscapeUrlEncodedData(source, true); |
| 453 return StringPrintf(kOAuthLoginFormat, | 453 return base::StringPrintf(kOAuthLoginFormat, |
| 454 encoded_service.c_str(), | 454 encoded_service.c_str(), |
| 455 encoded_source.c_str()); | 455 encoded_source.c_str()); |
| 456 } | 456 } |
| 457 | 457 |
| 458 // static | 458 // static |
| 459 void GaiaAuthFetcher::ParseClientLoginFailure(const std::string& data, | 459 void GaiaAuthFetcher::ParseClientLoginFailure(const std::string& data, |
| 460 std::string* error, | 460 std::string* error, |
| 461 std::string* error_url, | 461 std::string* error_url, |
| 462 std::string* captcha_url, | 462 std::string* captcha_url, |
| 463 std::string* captcha_token) { | 463 std::string* captcha_token) { |
| 464 using std::vector; | 464 using std::vector; |
| 465 using std::pair; | 465 using std::pair; |
| (...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1122 NOTREACHED(); | 1122 NOTREACHED(); |
| 1123 } | 1123 } |
| 1124 } | 1124 } |
| 1125 | 1125 |
| 1126 // static | 1126 // static |
| 1127 bool GaiaAuthFetcher::IsSecondFactorSuccess( | 1127 bool GaiaAuthFetcher::IsSecondFactorSuccess( |
| 1128 const std::string& alleged_error) { | 1128 const std::string& alleged_error) { |
| 1129 return alleged_error.find(kSecondFactor) != | 1129 return alleged_error.find(kSecondFactor) != |
| 1130 std::string::npos; | 1130 std::string::npos; |
| 1131 } | 1131 } |
| OLD | NEW |