Commit 80f645c4 authored by xiyuan's avatar xiyuan Committed by Commit bot

easy-unlock: Fix AttemptAuth email CHECK crash

- Return canonicalized email from GetUserEmail because sign-in
  manager gives back the Gaia email which is not necessarily the
  same as the one used on the login screen;
- Sign-in manager gives empty user email when underlying refresh token
  is revoked. Bail out in this case.

BUG=489890

Review URL: https://codereview.chromium.org/1149873003

Cr-Commit-Position: refs/heads/master@{#330890}
parent 62ba7d56
...@@ -493,13 +493,24 @@ void EasyUnlockService::AttemptAuth(const std::string& user_id) { ...@@ -493,13 +493,24 @@ void EasyUnlockService::AttemptAuth(const std::string& user_id) {
void EasyUnlockService::AttemptAuth(const std::string& user_id, void EasyUnlockService::AttemptAuth(const std::string& user_id,
const AttemptAuthCallback& callback) { const AttemptAuthCallback& callback) {
const EasyUnlockAuthAttempt::Type auth_attempt_type =
GetType() == TYPE_REGULAR ? EasyUnlockAuthAttempt::TYPE_UNLOCK
: EasyUnlockAuthAttempt::TYPE_SIGNIN;
const std::string user_email = GetUserEmail();
if (user_email.empty()) {
LOG(ERROR) << "Empty user email. Refresh token might go bad.";
if (!callback.is_null()) {
const bool kFailure = false;
callback.Run(auth_attempt_type, kFailure, user_id, std::string(),
std::string());
}
return;
}
CHECK_EQ(GetUserEmail(), user_id); CHECK_EQ(GetUserEmail(), user_id);
auth_attempt_.reset(new EasyUnlockAuthAttempt( auth_attempt_.reset(new EasyUnlockAuthAttempt(app_manager_.get(), user_id,
app_manager_.get(), user_id, auth_attempt_type, callback));
GetType() == TYPE_REGULAR ? EasyUnlockAuthAttempt::TYPE_UNLOCK
: EasyUnlockAuthAttempt::TYPE_SIGNIN,
callback));
if (!auth_attempt_->Start()) if (!auth_attempt_->Start())
auth_attempt_.reset(); auth_attempt_.reset();
} }
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "extensions/browser/event_router.h" #include "extensions/browser/event_router.h"
#include "extensions/common/constants.h" #include "extensions/common/constants.h"
#include "google_apis/gaia/gaia_auth_util.h"
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
#include "apps/app_lifetime_monitor_factory.h" #include "apps/app_lifetime_monitor_factory.h"
...@@ -98,7 +99,8 @@ std::string EasyUnlockServiceRegular::GetUserEmail() const { ...@@ -98,7 +99,8 @@ std::string EasyUnlockServiceRegular::GetUserEmail() const {
// |profile| has to be a signed-in profile with SigninManager already // |profile| has to be a signed-in profile with SigninManager already
// created. Otherwise, just crash to collect stack. // created. Otherwise, just crash to collect stack.
DCHECK(signin_manager); DCHECK(signin_manager);
return signin_manager->GetAuthenticatedUsername(); const std::string user_email = signin_manager->GetAuthenticatedUsername();
return user_email.empty() ? user_email : gaia::CanonicalizeEmail(user_email);
} }
void EasyUnlockServiceRegular::LaunchSetup() { void EasyUnlockServiceRegular::LaunchSetup() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment