| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 const std::string& password, | 297 const std::string& password, |
| 298 const char* const service, | 298 const char* const service, |
| 299 const std::string& login_token, | 299 const std::string& login_token, |
| 300 const std::string& login_captcha, | 300 const std::string& login_captcha, |
| 301 HostedAccountsSetting allow_hosted_accounts) { | 301 HostedAccountsSetting allow_hosted_accounts) { |
| 302 | 302 |
| 303 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; | 303 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; |
| 304 | 304 |
| 305 // This class is thread agnostic, so be sure to call this only on the | 305 // This class is thread agnostic, so be sure to call this only on the |
| 306 // same thread each time. | 306 // same thread each time. |
| 307 VLOG(1) << "Starting new ClientLogin fetch for:" << username; | 307 DVLOG(1) << "Starting new ClientLogin fetch for:" << username; |
| 308 | 308 |
| 309 // Must outlive fetcher_. | 309 // Must outlive fetcher_. |
| 310 request_body_ = MakeClientLoginBody(username, | 310 request_body_ = MakeClientLoginBody(username, |
| 311 password, | 311 password, |
| 312 source_, | 312 source_, |
| 313 service, | 313 service, |
| 314 login_token, | 314 login_token, |
| 315 login_captcha, | 315 login_captcha, |
| 316 allow_hosted_accounts); | 316 allow_hosted_accounts); |
| 317 fetcher_.reset(CreateGaiaFetcher(getter_, | 317 fetcher_.reset(CreateGaiaFetcher(getter_, |
| 318 request_body_, | 318 request_body_, |
| 319 client_login_gurl_, | 319 client_login_gurl_, |
| 320 false, | 320 false, |
| 321 this)); | 321 this)); |
| 322 fetch_pending_ = true; | 322 fetch_pending_ = true; |
| 323 fetcher_->Start(); | 323 fetcher_->Start(); |
| 324 } | 324 } |
| 325 | 325 |
| 326 void GaiaAuthFetcher::StartIssueAuthToken(const std::string& sid, | 326 void GaiaAuthFetcher::StartIssueAuthToken(const std::string& sid, |
| 327 const std::string& lsid, | 327 const std::string& lsid, |
| 328 const char* const service) { | 328 const char* const service) { |
| 329 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; | 329 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; |
| 330 | 330 |
| 331 VLOG(1) << "Starting IssueAuthToken for: " << service; | 331 DVLOG(1) << "Starting IssueAuthToken for: " << service; |
| 332 requested_service_ = service; | 332 requested_service_ = service; |
| 333 request_body_ = MakeIssueAuthTokenBody(sid, lsid, service); | 333 request_body_ = MakeIssueAuthTokenBody(sid, lsid, service); |
| 334 fetcher_.reset(CreateGaiaFetcher(getter_, | 334 fetcher_.reset(CreateGaiaFetcher(getter_, |
| 335 request_body_, | 335 request_body_, |
| 336 issue_auth_token_gurl_, | 336 issue_auth_token_gurl_, |
| 337 false, | 337 false, |
| 338 this)); | 338 this)); |
| 339 fetch_pending_ = true; | 339 fetch_pending_ = true; |
| 340 fetcher_->Start(); | 340 fetcher_->Start(); |
| 341 } | 341 } |
| 342 | 342 |
| 343 void GaiaAuthFetcher::StartGetUserInfo(const std::string& lsid, | 343 void GaiaAuthFetcher::StartGetUserInfo(const std::string& lsid, |
| 344 const std::string& info_key) { | 344 const std::string& info_key) { |
| 345 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; | 345 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; |
| 346 | 346 |
| 347 VLOG(1) << "Starting GetUserInfo for lsid=" << lsid; | 347 DVLOG(1) << "Starting GetUserInfo for lsid=" << lsid; |
| 348 request_body_ = MakeGetUserInfoBody(lsid); | 348 request_body_ = MakeGetUserInfoBody(lsid); |
| 349 fetcher_.reset(CreateGaiaFetcher(getter_, | 349 fetcher_.reset(CreateGaiaFetcher(getter_, |
| 350 request_body_, | 350 request_body_, |
| 351 get_user_info_gurl_, | 351 get_user_info_gurl_, |
| 352 false, | 352 false, |
| 353 this)); | 353 this)); |
| 354 fetch_pending_ = true; | 354 fetch_pending_ = true; |
| 355 requested_info_key_ = info_key; | 355 requested_info_key_ = info_key; |
| 356 fetcher_->Start(); | 356 fetcher_->Start(); |
| 357 } | 357 } |
| 358 | 358 |
| 359 void GaiaAuthFetcher::StartTokenAuth(const std::string& auth_token) { | 359 void GaiaAuthFetcher::StartTokenAuth(const std::string& auth_token) { |
| 360 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; | 360 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; |
| 361 | 361 |
| 362 VLOG(1) << "Starting TokenAuth with auth_token=" << auth_token; | 362 DVLOG(1) << "Starting TokenAuth with auth_token=" << auth_token; |
| 363 | 363 |
| 364 // The continue URL is a required parameter of the TokenAuth API, but in this | 364 // The continue URL is a required parameter of the TokenAuth API, but in this |
| 365 // case we don't actually need or want to navigate to it. Setting it to | 365 // case we don't actually need or want to navigate to it. Setting it to |
| 366 // an arbitrary Google URL. | 366 // an arbitrary Google URL. |
| 367 std::string continue_url("http://www.google.com"); | 367 std::string continue_url("http://www.google.com"); |
| 368 request_body_ = MakeTokenAuthBody(auth_token, continue_url, source_); | 368 request_body_ = MakeTokenAuthBody(auth_token, continue_url, source_); |
| 369 fetcher_.reset(CreateGaiaFetcher(getter_, | 369 fetcher_.reset(CreateGaiaFetcher(getter_, |
| 370 request_body_, | 370 request_body_, |
| 371 token_auth_gurl_, | 371 token_auth_gurl_, |
| 372 false, | 372 false, |
| 373 this)); | 373 this)); |
| 374 fetch_pending_ = true; | 374 fetch_pending_ = true; |
| 375 fetcher_->Start(); | 375 fetcher_->Start(); |
| 376 } | 376 } |
| 377 | 377 |
| 378 void GaiaAuthFetcher::StartMergeSession(const std::string& auth_token) { | 378 void GaiaAuthFetcher::StartMergeSession(const std::string& auth_token) { |
| 379 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; | 379 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; |
| 380 | 380 |
| 381 VLOG(1) << "Starting MergeSession with auth_token=" << auth_token; | 381 DVLOG(1) << "Starting MergeSession with auth_token=" << auth_token; |
| 382 | 382 |
| 383 // The continue URL is a required parameter of the MergeSession API, but in | 383 // The continue URL is a required parameter of the MergeSession API, but in |
| 384 // this case we don't actually need or want to navigate to it. Setting it to | 384 // this case we don't actually need or want to navigate to it. Setting it to |
| 385 // an arbitrary Google URL. | 385 // an arbitrary Google URL. |
| 386 // | 386 // |
| 387 // In order for the new session to be merged correctly, the server needs to | 387 // In order for the new session to be merged correctly, the server needs to |
| 388 // know what sessions already exist in the browser. The fetcher needs to be | 388 // know what sessions already exist in the browser. The fetcher needs to be |
| 389 // created such that it sends the cookies with the request, which is | 389 // created such that it sends the cookies with the request, which is |
| 390 // different from all other requests the fetcher can make. | 390 // different from all other requests the fetcher can make. |
| 391 std::string continue_url("http://www.google.com"); | 391 std::string continue_url("http://www.google.com"); |
| 392 request_body_ = MakeMergeSessionBody(auth_token, continue_url, source_); | 392 request_body_ = MakeMergeSessionBody(auth_token, continue_url, source_); |
| 393 fetcher_.reset(CreateGaiaFetcher(getter_, | 393 fetcher_.reset(CreateGaiaFetcher(getter_, |
| 394 request_body_, | 394 request_body_, |
| 395 merge_session_gurl_, | 395 merge_session_gurl_, |
| 396 true, | 396 true, |
| 397 this)); | 397 this)); |
| 398 fetch_pending_ = true; | 398 fetch_pending_ = true; |
| 399 fetcher_->Start(); | 399 fetcher_->Start(); |
| 400 } | 400 } |
| 401 | 401 |
| 402 // static | 402 // static |
| 403 GoogleServiceAuthError GaiaAuthFetcher::GenerateAuthError( | 403 GoogleServiceAuthError GaiaAuthFetcher::GenerateAuthError( |
| 404 const std::string& data, | 404 const std::string& data, |
| 405 const net::URLRequestStatus& status) { | 405 const net::URLRequestStatus& status) { |
| 406 if (!status.is_success()) { | 406 if (!status.is_success()) { |
| 407 if (status.status() == net::URLRequestStatus::CANCELED) { | 407 if (status.status() == net::URLRequestStatus::CANCELED) { |
| 408 return GoogleServiceAuthError(GoogleServiceAuthError::REQUEST_CANCELED); | 408 return GoogleServiceAuthError(GoogleServiceAuthError::REQUEST_CANCELED); |
| 409 } else { | 409 } else { |
| 410 LOG(WARNING) << "Could not reach Google Accounts servers: errno " | 410 DLOG(WARNING) << "Could not reach Google Accounts servers: errno " |
| 411 << status.error(); | 411 << status.error(); |
| 412 return GoogleServiceAuthError::FromConnectionError(status.error()); | 412 return GoogleServiceAuthError::FromConnectionError(status.error()); |
| 413 } | 413 } |
| 414 } else { | 414 } else { |
| 415 if (IsSecondFactorSuccess(data)) { | 415 if (IsSecondFactorSuccess(data)) { |
| 416 return GoogleServiceAuthError(GoogleServiceAuthError::TWO_FACTOR); | 416 return GoogleServiceAuthError(GoogleServiceAuthError::TWO_FACTOR); |
| 417 } | 417 } |
| 418 | 418 |
| 419 std::string error; | 419 std::string error; |
| 420 std::string url; | 420 std::string url; |
| 421 std::string captcha_url; | 421 std::string captcha_url; |
| 422 std::string captcha_token; | 422 std::string captcha_token; |
| 423 ParseClientLoginFailure(data, &error, &url, &captcha_url, &captcha_token); | 423 ParseClientLoginFailure(data, &error, &url, &captcha_url, &captcha_token); |
| 424 LOG(WARNING) << "ClientLogin failed with " << error; | 424 DLOG(WARNING) << "ClientLogin failed with " << error; |
| 425 | 425 |
| 426 if (error == kCaptchaError) { | 426 if (error == kCaptchaError) { |
| 427 GURL image_url( | 427 GURL image_url( |
| 428 GaiaUrls::GetInstance()->captcha_url_prefix() + captcha_url); | 428 GaiaUrls::GetInstance()->captcha_url_prefix() + captcha_url); |
| 429 GURL unlock_url(url); | 429 GURL unlock_url(url); |
| 430 return GoogleServiceAuthError::FromCaptchaChallenge( | 430 return GoogleServiceAuthError::FromCaptchaChallenge( |
| 431 captcha_token, image_url, unlock_url); | 431 captcha_token, image_url, unlock_url); |
| 432 } | 432 } |
| 433 if (error == kAccountDeletedError) | 433 if (error == kAccountDeletedError) |
| 434 return GoogleServiceAuthError(GoogleServiceAuthError::ACCOUNT_DELETED); | 434 return GoogleServiceAuthError(GoogleServiceAuthError::ACCOUNT_DELETED); |
| 435 if (error == kAccountDisabledError) | 435 if (error == kAccountDisabledError) |
| 436 return GoogleServiceAuthError(GoogleServiceAuthError::ACCOUNT_DISABLED); | 436 return GoogleServiceAuthError(GoogleServiceAuthError::ACCOUNT_DISABLED); |
| 437 if (error == kBadAuthenticationError) { | 437 if (error == kBadAuthenticationError) { |
| 438 return GoogleServiceAuthError( | 438 return GoogleServiceAuthError( |
| 439 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | 439 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
| 440 } | 440 } |
| 441 if (error == kServiceUnavailableError) { | 441 if (error == kServiceUnavailableError) { |
| 442 return GoogleServiceAuthError( | 442 return GoogleServiceAuthError( |
| 443 GoogleServiceAuthError::SERVICE_UNAVAILABLE); | 443 GoogleServiceAuthError::SERVICE_UNAVAILABLE); |
| 444 } | 444 } |
| 445 | 445 |
| 446 LOG(WARNING) << "Incomprehensible response from Google Accounts servers."; | 446 DLOG(WARNING) << "Incomprehensible response from Google Accounts servers."; |
| 447 return GoogleServiceAuthError( | 447 return GoogleServiceAuthError( |
| 448 GoogleServiceAuthError::SERVICE_UNAVAILABLE); | 448 GoogleServiceAuthError::SERVICE_UNAVAILABLE); |
| 449 } | 449 } |
| 450 | 450 |
| 451 NOTREACHED(); | 451 NOTREACHED(); |
| 452 return GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_UNAVAILABLE); | 452 return GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_UNAVAILABLE); |
| 453 } | 453 } |
| 454 | 454 |
| 455 // static | 455 // static |
| 456 GoogleServiceAuthError GaiaAuthFetcher::GenerateOAuthLoginError( | 456 GoogleServiceAuthError GaiaAuthFetcher::GenerateOAuthLoginError( |
| 457 const std::string& data, | 457 const std::string& data, |
| 458 const net::URLRequestStatus& status) { | 458 const net::URLRequestStatus& status) { |
| 459 if (!status.is_success()) { | 459 if (!status.is_success()) { |
| 460 if (status.status() == net::URLRequestStatus::CANCELED) { | 460 if (status.status() == net::URLRequestStatus::CANCELED) { |
| 461 return GoogleServiceAuthError(GoogleServiceAuthError::REQUEST_CANCELED); | 461 return GoogleServiceAuthError(GoogleServiceAuthError::REQUEST_CANCELED); |
| 462 } else { | 462 } else { |
| 463 LOG(WARNING) << "Could not reach Google Accounts servers: errno " | 463 DLOG(WARNING) << "Could not reach Google Accounts servers: errno " |
| 464 << status.error(); | 464 << status.error(); |
| 465 return GoogleServiceAuthError::FromConnectionError(status.error()); | 465 return GoogleServiceAuthError::FromConnectionError(status.error()); |
| 466 } | 466 } |
| 467 } else { | 467 } else { |
| 468 if (IsSecondFactorSuccess(data)) { | 468 if (IsSecondFactorSuccess(data)) { |
| 469 return GoogleServiceAuthError(GoogleServiceAuthError::TWO_FACTOR); | 469 return GoogleServiceAuthError(GoogleServiceAuthError::TWO_FACTOR); |
| 470 } | 470 } |
| 471 | 471 |
| 472 std::string error; | 472 std::string error; |
| 473 std::string url; | 473 std::string url; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 489 return GoogleServiceAuthError(GoogleServiceAuthError::ACCOUNT_DISABLED); | 489 return GoogleServiceAuthError(GoogleServiceAuthError::ACCOUNT_DISABLED); |
| 490 if (error == kBadAuthenticationErrorCode) { | 490 if (error == kBadAuthenticationErrorCode) { |
| 491 return GoogleServiceAuthError( | 491 return GoogleServiceAuthError( |
| 492 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | 492 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
| 493 } | 493 } |
| 494 if (error == kServiceUnavailableErrorCode) { | 494 if (error == kServiceUnavailableErrorCode) { |
| 495 return GoogleServiceAuthError( | 495 return GoogleServiceAuthError( |
| 496 GoogleServiceAuthError::SERVICE_UNAVAILABLE); | 496 GoogleServiceAuthError::SERVICE_UNAVAILABLE); |
| 497 } | 497 } |
| 498 | 498 |
| 499 LOG(WARNING) << "Incomprehensible response from Google Accounts servers."; | 499 DLOG(WARNING) << "Incomprehensible response from Google Accounts servers."; |
| 500 return GoogleServiceAuthError( | 500 return GoogleServiceAuthError( |
| 501 GoogleServiceAuthError::SERVICE_UNAVAILABLE); | 501 GoogleServiceAuthError::SERVICE_UNAVAILABLE); |
| 502 } | 502 } |
| 503 | 503 |
| 504 NOTREACHED(); | 504 NOTREACHED(); |
| 505 return GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_UNAVAILABLE); | 505 return GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_UNAVAILABLE); |
| 506 } | 506 } |
| 507 | 507 |
| 508 void GaiaAuthFetcher::OnClientLoginFetched(const std::string& data, | 508 void GaiaAuthFetcher::OnClientLoginFetched(const std::string& data, |
| 509 const net::URLRequestStatus& status, | 509 const net::URLRequestStatus& status, |
| 510 int response_code) { | 510 int response_code) { |
| 511 if (status.is_success() && response_code == RC_REQUEST_OK) { | 511 if (status.is_success() && response_code == RC_REQUEST_OK) { |
| 512 VLOG(1) << "ClientLogin successful!"; | 512 DVLOG(1) << "ClientLogin successful!"; |
| 513 std::string sid; | 513 std::string sid; |
| 514 std::string lsid; | 514 std::string lsid; |
| 515 std::string token; | 515 std::string token; |
| 516 ParseClientLoginResponse(data, &sid, &lsid, &token); | 516 ParseClientLoginResponse(data, &sid, &lsid, &token); |
| 517 consumer_->OnClientLoginSuccess( | 517 consumer_->OnClientLoginSuccess( |
| 518 GaiaAuthConsumer::ClientLoginResult(sid, lsid, token, data)); | 518 GaiaAuthConsumer::ClientLoginResult(sid, lsid, token, data)); |
| 519 } else { | 519 } else { |
| 520 consumer_->OnClientLoginFailure(GenerateAuthError(data, status)); | 520 consumer_->OnClientLoginFailure(GenerateAuthError(data, status)); |
| 521 } | 521 } |
| 522 } | 522 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 NOTREACHED(); | 602 NOTREACHED(); |
| 603 } | 603 } |
| 604 } | 604 } |
| 605 | 605 |
| 606 // static | 606 // static |
| 607 bool GaiaAuthFetcher::IsSecondFactorSuccess( | 607 bool GaiaAuthFetcher::IsSecondFactorSuccess( |
| 608 const std::string& alleged_error) { | 608 const std::string& alleged_error) { |
| 609 return alleged_error.find(kSecondFactor) != | 609 return alleged_error.find(kSecondFactor) != |
| 610 std::string::npos; | 610 std::string::npos; |
| 611 } | 611 } |
| OLD | NEW |