OLD | NEW |
1 // Copyright (c) 2010 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 |
11 #include "base/string_split.h" | 11 #include "base/string_split.h" |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 get_user_info_gurl_, | 307 get_user_info_gurl_, |
308 this)); | 308 this)); |
309 fetch_pending_ = true; | 309 fetch_pending_ = true; |
310 requested_info_key_ = info_key; | 310 requested_info_key_ = info_key; |
311 fetcher_->Start(); | 311 fetcher_->Start(); |
312 } | 312 } |
313 | 313 |
314 // static | 314 // static |
315 GoogleServiceAuthError GaiaAuthFetcher::GenerateAuthError( | 315 GoogleServiceAuthError GaiaAuthFetcher::GenerateAuthError( |
316 const std::string& data, | 316 const std::string& data, |
317 const URLRequestStatus& status) { | 317 const net::URLRequestStatus& status) { |
318 | 318 |
319 if (!status.is_success()) { | 319 if (!status.is_success()) { |
320 if (status.status() == URLRequestStatus::CANCELED) { | 320 if (status.status() == net::URLRequestStatus::CANCELED) { |
321 return GoogleServiceAuthError(GoogleServiceAuthError::REQUEST_CANCELED); | 321 return GoogleServiceAuthError(GoogleServiceAuthError::REQUEST_CANCELED); |
322 } else { | 322 } else { |
323 LOG(WARNING) << "Could not reach Google Accounts servers: errno " | 323 LOG(WARNING) << "Could not reach Google Accounts servers: errno " |
324 << status.os_error(); | 324 << status.os_error(); |
325 return GoogleServiceAuthError::FromConnectionError(status.os_error()); | 325 return GoogleServiceAuthError::FromConnectionError(status.os_error()); |
326 } | 326 } |
327 } else { | 327 } else { |
328 if (IsSecondFactorSuccess(data)) { | 328 if (IsSecondFactorSuccess(data)) { |
329 return GoogleServiceAuthError(GoogleServiceAuthError::TWO_FACTOR); | 329 return GoogleServiceAuthError(GoogleServiceAuthError::TWO_FACTOR); |
330 } | 330 } |
(...skipping 26 matching lines...) Expand all Loading... |
357 | 357 |
358 LOG(WARNING) << "Incomprehensible response from Google Accounts servers."; | 358 LOG(WARNING) << "Incomprehensible response from Google Accounts servers."; |
359 return GoogleServiceAuthError( | 359 return GoogleServiceAuthError( |
360 GoogleServiceAuthError::SERVICE_UNAVAILABLE); | 360 GoogleServiceAuthError::SERVICE_UNAVAILABLE); |
361 } | 361 } |
362 | 362 |
363 NOTREACHED(); | 363 NOTREACHED(); |
364 } | 364 } |
365 | 365 |
366 void GaiaAuthFetcher::OnClientLoginFetched(const std::string& data, | 366 void GaiaAuthFetcher::OnClientLoginFetched(const std::string& data, |
367 const URLRequestStatus& status, | 367 const net::URLRequestStatus& status, |
368 int response_code) { | 368 int response_code) { |
369 | 369 |
370 if (status.is_success() && response_code == RC_REQUEST_OK) { | 370 if (status.is_success() && response_code == RC_REQUEST_OK) { |
371 VLOG(1) << "ClientLogin successful!"; | 371 VLOG(1) << "ClientLogin successful!"; |
372 std::string sid; | 372 std::string sid; |
373 std::string lsid; | 373 std::string lsid; |
374 std::string token; | 374 std::string token; |
375 ParseClientLoginResponse(data, &sid, &lsid, &token); | 375 ParseClientLoginResponse(data, &sid, &lsid, &token); |
376 consumer_->OnClientLoginSuccess( | 376 consumer_->OnClientLoginSuccess( |
377 GaiaAuthConsumer::ClientLoginResult(sid, lsid, token, data)); | 377 GaiaAuthConsumer::ClientLoginResult(sid, lsid, token, data)); |
378 } else { | 378 } else { |
379 consumer_->OnClientLoginFailure(GenerateAuthError(data, status)); | 379 consumer_->OnClientLoginFailure(GenerateAuthError(data, status)); |
380 } | 380 } |
381 } | 381 } |
382 | 382 |
383 void GaiaAuthFetcher::OnIssueAuthTokenFetched( | 383 void GaiaAuthFetcher::OnIssueAuthTokenFetched( |
384 const std::string& data, | 384 const std::string& data, |
385 const URLRequestStatus& status, | 385 const net::URLRequestStatus& status, |
386 int response_code) { | 386 int response_code) { |
387 if (status.is_success() && response_code == RC_REQUEST_OK) { | 387 if (status.is_success() && response_code == RC_REQUEST_OK) { |
388 // Only the bare token is returned in the body of this Gaia call | 388 // Only the bare token is returned in the body of this Gaia call |
389 // without any padding. | 389 // without any padding. |
390 consumer_->OnIssueAuthTokenSuccess(requested_service_, data); | 390 consumer_->OnIssueAuthTokenSuccess(requested_service_, data); |
391 } else { | 391 } else { |
392 consumer_->OnIssueAuthTokenFailure(requested_service_, | 392 consumer_->OnIssueAuthTokenFailure(requested_service_, |
393 GenerateAuthError(data, status)); | 393 GenerateAuthError(data, status)); |
394 } | 394 } |
395 } | 395 } |
396 | 396 |
397 void GaiaAuthFetcher::OnGetUserInfoFetched( | 397 void GaiaAuthFetcher::OnGetUserInfoFetched( |
398 const std::string& data, | 398 const std::string& data, |
399 const URLRequestStatus& status, | 399 const net::URLRequestStatus& status, |
400 int response_code) { | 400 int response_code) { |
401 using std::vector; | 401 using std::vector; |
402 using std::string; | 402 using std::string; |
403 using std::pair; | 403 using std::pair; |
404 | 404 |
405 if (status.is_success() && response_code == RC_REQUEST_OK) { | 405 if (status.is_success() && response_code == RC_REQUEST_OK) { |
406 vector<pair<string, string> > tokens; | 406 vector<pair<string, string> > tokens; |
407 base::SplitStringIntoKeyValuePairs(data, '=', '\n', &tokens); | 407 base::SplitStringIntoKeyValuePairs(data, '=', '\n', &tokens); |
408 for (vector<pair<string, string> >::iterator i = tokens.begin(); | 408 for (vector<pair<string, string> >::iterator i = tokens.begin(); |
409 i != tokens.end(); ++i) { | 409 i != tokens.end(); ++i) { |
410 if (i->first == requested_info_key_) { | 410 if (i->first == requested_info_key_) { |
411 consumer_->OnGetUserInfoSuccess(i->first, i->second); | 411 consumer_->OnGetUserInfoSuccess(i->first, i->second); |
412 return; | 412 return; |
413 } | 413 } |
414 } | 414 } |
415 consumer_->OnGetUserInfoKeyNotFound(requested_info_key_); | 415 consumer_->OnGetUserInfoKeyNotFound(requested_info_key_); |
416 } else { | 416 } else { |
417 consumer_->OnGetUserInfoFailure(GenerateAuthError(data, status)); | 417 consumer_->OnGetUserInfoFailure(GenerateAuthError(data, status)); |
418 } | 418 } |
419 } | 419 } |
420 | 420 |
421 void GaiaAuthFetcher::OnURLFetchComplete(const URLFetcher* source, | 421 void GaiaAuthFetcher::OnURLFetchComplete(const URLFetcher* source, |
422 const GURL& url, | 422 const GURL& url, |
423 const URLRequestStatus& status, | 423 const net::URLRequestStatus& status, |
424 int response_code, | 424 int response_code, |
425 const ResponseCookies& cookies, | 425 const ResponseCookies& cookies, |
426 const std::string& data) { | 426 const std::string& data) { |
427 fetch_pending_ = false; | 427 fetch_pending_ = false; |
428 if (url == client_login_gurl_) { | 428 if (url == client_login_gurl_) { |
429 OnClientLoginFetched(data, status, response_code); | 429 OnClientLoginFetched(data, status, response_code); |
430 } else if (url == issue_auth_token_gurl_) { | 430 } else if (url == issue_auth_token_gurl_) { |
431 OnIssueAuthTokenFetched(data, status, response_code); | 431 OnIssueAuthTokenFetched(data, status, response_code); |
432 } else if (url == get_user_info_gurl_) { | 432 } else if (url == get_user_info_gurl_) { |
433 OnGetUserInfoFetched(data, status, response_code); | 433 OnGetUserInfoFetched(data, status, response_code); |
434 } else { | 434 } else { |
435 NOTREACHED(); | 435 NOTREACHED(); |
436 } | 436 } |
437 } | 437 } |
438 | 438 |
439 // static | 439 // static |
440 bool GaiaAuthFetcher::IsSecondFactorSuccess( | 440 bool GaiaAuthFetcher::IsSecondFactorSuccess( |
441 const std::string& alleged_error) { | 441 const std::string& alleged_error) { |
442 return alleged_error.find(kSecondFactor) != | 442 return alleged_error.find(kSecondFactor) != |
443 std::string::npos; | 443 std::string::npos; |
444 } | 444 } |
OLD | NEW |