| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_authenticator2.h" | 5 #include "chrome/common/net/gaia/gaia_authenticator2.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 const std::string& password, | 245 const std::string& password, |
| 246 const char* const service, | 246 const char* const service, |
| 247 const std::string& login_token, | 247 const std::string& login_token, |
| 248 const std::string& login_captcha, | 248 const std::string& login_captcha, |
| 249 HostedAccountsSetting allow_hosted_accounts) { | 249 HostedAccountsSetting allow_hosted_accounts) { |
| 250 | 250 |
| 251 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; | 251 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; |
| 252 | 252 |
| 253 // This class is thread agnostic, so be sure to call this only on the | 253 // This class is thread agnostic, so be sure to call this only on the |
| 254 // same thread each time. | 254 // same thread each time. |
| 255 LOG(INFO) << "Starting new ClientLogin fetch for:" << username; | 255 VLOG(1) << "Starting new ClientLogin fetch for:" << username; |
| 256 | 256 |
| 257 // Must outlive fetcher_. | 257 // Must outlive fetcher_. |
| 258 request_body_ = MakeClientLoginBody(username, | 258 request_body_ = MakeClientLoginBody(username, |
| 259 password, | 259 password, |
| 260 source_, | 260 source_, |
| 261 service, | 261 service, |
| 262 login_token, | 262 login_token, |
| 263 login_captcha, | 263 login_captcha, |
| 264 allow_hosted_accounts); | 264 allow_hosted_accounts); |
| 265 fetcher_.reset(CreateGaiaFetcher(getter_, | 265 fetcher_.reset(CreateGaiaFetcher(getter_, |
| 266 request_body_, | 266 request_body_, |
| 267 client_login_gurl_, | 267 client_login_gurl_, |
| 268 this)); | 268 this)); |
| 269 fetch_pending_ = true; | 269 fetch_pending_ = true; |
| 270 fetcher_->Start(); | 270 fetcher_->Start(); |
| 271 } | 271 } |
| 272 | 272 |
| 273 void GaiaAuthenticator2::StartIssueAuthToken(const std::string& sid, | 273 void GaiaAuthenticator2::StartIssueAuthToken(const std::string& sid, |
| 274 const std::string& lsid, | 274 const std::string& lsid, |
| 275 const char* const service) { | 275 const char* const service) { |
| 276 | 276 |
| 277 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; | 277 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; |
| 278 | 278 |
| 279 LOG(INFO) << "Starting IssueAuthToken for: " << service; | 279 VLOG(1) << "Starting IssueAuthToken for: " << service; |
| 280 requested_service_ = service; | 280 requested_service_ = service; |
| 281 request_body_ = MakeIssueAuthTokenBody(sid, lsid, service); | 281 request_body_ = MakeIssueAuthTokenBody(sid, lsid, service); |
| 282 fetcher_.reset(CreateGaiaFetcher(getter_, | 282 fetcher_.reset(CreateGaiaFetcher(getter_, |
| 283 request_body_, | 283 request_body_, |
| 284 issue_auth_token_gurl_, | 284 issue_auth_token_gurl_, |
| 285 this)); | 285 this)); |
| 286 fetch_pending_ = true; | 286 fetch_pending_ = true; |
| 287 fetcher_->Start(); | 287 fetcher_->Start(); |
| 288 } | 288 } |
| 289 | 289 |
| 290 void GaiaAuthenticator2::StartGetUserInfo(const std::string& lsid, | 290 void GaiaAuthenticator2::StartGetUserInfo(const std::string& lsid, |
| 291 const std::string& info_key) { | 291 const std::string& info_key) { |
| 292 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; | 292 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; |
| 293 | 293 |
| 294 LOG(INFO) << "Starting GetUserInfo for lsid=" << lsid; | 294 VLOG(1) << "Starting GetUserInfo for lsid=" << lsid; |
| 295 request_body_ = MakeGetUserInfoBody(lsid); | 295 request_body_ = MakeGetUserInfoBody(lsid); |
| 296 fetcher_.reset(CreateGaiaFetcher(getter_, | 296 fetcher_.reset(CreateGaiaFetcher(getter_, |
| 297 request_body_, | 297 request_body_, |
| 298 get_user_info_gurl_, | 298 get_user_info_gurl_, |
| 299 this)); | 299 this)); |
| 300 fetch_pending_ = true; | 300 fetch_pending_ = true; |
| 301 requested_info_key_ = info_key; | 301 requested_info_key_ = info_key; |
| 302 fetcher_->Start(); | 302 fetcher_->Start(); |
| 303 } | 303 } |
| 304 | 304 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 325 std::string captcha_url; | 325 std::string captcha_url; |
| 326 std::string captcha_token; | 326 std::string captcha_token; |
| 327 ParseClientLoginFailure(data, &error, &url, &captcha_url, &captcha_token); | 327 ParseClientLoginFailure(data, &error, &url, &captcha_url, &captcha_token); |
| 328 LOG(WARNING) << "ClientLogin failed with " << error; | 328 LOG(WARNING) << "ClientLogin failed with " << error; |
| 329 | 329 |
| 330 if (error == kCaptchaError) { | 330 if (error == kCaptchaError) { |
| 331 GURL image_url(kCaptchaUrlPrefix + captcha_url); | 331 GURL image_url(kCaptchaUrlPrefix + captcha_url); |
| 332 GURL unlock_url(url); | 332 GURL unlock_url(url); |
| 333 return GoogleServiceAuthError::FromCaptchaChallenge( | 333 return GoogleServiceAuthError::FromCaptchaChallenge( |
| 334 captcha_token, image_url, unlock_url); | 334 captcha_token, image_url, unlock_url); |
| 335 } else if (error == kAccountDeletedError) { | 335 } |
| 336 if (error == kAccountDeletedError) |
| 336 return GoogleServiceAuthError(GoogleServiceAuthError::ACCOUNT_DELETED); | 337 return GoogleServiceAuthError(GoogleServiceAuthError::ACCOUNT_DELETED); |
| 337 } else if (error == kAccountDisabledError) { | 338 if (error == kAccountDisabledError) |
| 338 return GoogleServiceAuthError(GoogleServiceAuthError::ACCOUNT_DISABLED); | 339 return GoogleServiceAuthError(GoogleServiceAuthError::ACCOUNT_DISABLED); |
| 339 } else if (error == kServiceUnavailableError) { | 340 if (error == kServiceUnavailableError) { |
| 340 return GoogleServiceAuthError( | 341 return GoogleServiceAuthError( |
| 341 GoogleServiceAuthError::SERVICE_UNAVAILABLE); | 342 GoogleServiceAuthError::SERVICE_UNAVAILABLE); |
| 342 } | 343 } |
| 343 | 344 |
| 344 return GoogleServiceAuthError( | 345 return GoogleServiceAuthError( |
| 345 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | 346 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
| 346 } | 347 } |
| 347 | 348 |
| 348 NOTREACHED(); | 349 NOTREACHED(); |
| 349 } | 350 } |
| 350 | 351 |
| 351 void GaiaAuthenticator2::OnClientLoginFetched(const std::string& data, | 352 void GaiaAuthenticator2::OnClientLoginFetched(const std::string& data, |
| 352 const URLRequestStatus& status, | 353 const URLRequestStatus& status, |
| 353 int response_code) { | 354 int response_code) { |
| 354 | 355 |
| 355 if (status.is_success() && response_code == RC_REQUEST_OK) { | 356 if (status.is_success() && response_code == RC_REQUEST_OK) { |
| 356 LOG(INFO) << "ClientLogin successful!"; | 357 VLOG(1) << "ClientLogin successful!"; |
| 357 std::string sid; | 358 std::string sid; |
| 358 std::string lsid; | 359 std::string lsid; |
| 359 std::string token; | 360 std::string token; |
| 360 ParseClientLoginResponse(data, &sid, &lsid, &token); | 361 ParseClientLoginResponse(data, &sid, &lsid, &token); |
| 361 consumer_->OnClientLoginSuccess( | 362 consumer_->OnClientLoginSuccess( |
| 362 GaiaAuthConsumer::ClientLoginResult(sid, lsid, token, data)); | 363 GaiaAuthConsumer::ClientLoginResult(sid, lsid, token, data)); |
| 363 } else { | 364 } else { |
| 364 consumer_->OnClientLoginFailure(GenerateAuthError(data, status)); | 365 consumer_->OnClientLoginFailure(GenerateAuthError(data, status)); |
| 365 } | 366 } |
| 366 } | 367 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 NOTREACHED(); | 421 NOTREACHED(); |
| 421 } | 422 } |
| 422 } | 423 } |
| 423 | 424 |
| 424 // static | 425 // static |
| 425 bool GaiaAuthenticator2::IsSecondFactorSuccess( | 426 bool GaiaAuthenticator2::IsSecondFactorSuccess( |
| 426 const std::string& alleged_error) { | 427 const std::string& alleged_error) { |
| 427 return alleged_error.find(kSecondFactor) != | 428 return alleged_error.find(kSecondFactor) != |
| 428 std::string::npos; | 429 std::string::npos; |
| 429 } | 430 } |
| OLD | NEW |