summaryrefslogtreecommitdiffstats
path: root/google_apis
diff options
context:
space:
mode:
authorguohui@chromium.org <guohui@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-17 04:01:24 +0000
committerguohui@chromium.org <guohui@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-17 04:01:24 +0000
commit5da3ebe20b39f982a1b4d9d7d6e55a959137d253 (patch)
treecac3df96cc1dceb9b23eb0c59dac4dd0d1c5b9fa /google_apis
parent6a98d94c2732fc81f862ebfa608fd0f23e84444f (diff)
downloadchromium_src-5da3ebe20b39f982a1b4d9d7d6e55a959137d253.zip
chromium_src-5da3ebe20b39f982a1b4d9d7d6e55a959137d253.tar.gz
chromium_src-5da3ebe20b39f982a1b4d9d7d6e55a959137d253.tar.bz2
Fix skip for now link with inline flow
For details, please refer to the attached bug BUG=328563, 329016 Review URL: https://codereview.chromium.org/115343005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@241148 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'google_apis')
-rw-r--r--google_apis/gaia/gaia_auth_consumer.h3
-rw-r--r--google_apis/gaia/gaia_auth_fetcher.cc22
-rw-r--r--google_apis/gaia/gaia_auth_fetcher.h12
-rw-r--r--google_apis/gaia/gaia_auth_fetcher_unittest.cc52
4 files changed, 86 insertions, 3 deletions
diff --git a/google_apis/gaia/gaia_auth_consumer.h b/google_apis/gaia/gaia_auth_consumer.h
index d5ab306..4dfabf7 100644
--- a/google_apis/gaia/gaia_auth_consumer.h
+++ b/google_apis/gaia/gaia_auth_consumer.h
@@ -72,6 +72,9 @@ class GaiaAuthConsumer {
virtual void OnClientOAuthSuccess(const ClientOAuthResult& result) {}
virtual void OnClientOAuthFailure(const GoogleServiceAuthError& error) {}
+ virtual void OnClientOAuthCodeSuccess(const std::string& auth_code) {}
+ virtual void OnClientOAuthCodeFailure(const GoogleServiceAuthError& error) {}
+
virtual void OnOAuth2RevokeTokenCompleted() {}
virtual void OnGetUserInfoSuccess(const UserInfoMap& data) {}
diff --git a/google_apis/gaia/gaia_auth_fetcher.cc b/google_apis/gaia/gaia_auth_fetcher.cc
index c5254f4..f3e85146 100644
--- a/google_apis/gaia/gaia_auth_fetcher.cc
+++ b/google_apis/gaia/gaia_auth_fetcher.cc
@@ -185,7 +185,8 @@ GaiaAuthFetcher::GaiaAuthFetcher(GaiaAuthConsumer* consumer,
list_accounts_gurl_(GaiaUrls::GetInstance()->list_accounts_url()),
client_login_to_oauth2_gurl_(
GaiaUrls::GetInstance()->client_login_to_oauth2_url()),
- fetch_pending_(false) {}
+ fetch_pending_(false),
+ fetch_code_only_(false) {}
GaiaAuthFetcher::~GaiaAuthFetcher() {}
@@ -545,6 +546,13 @@ void GaiaAuthFetcher::StartRevokeOAuth2Token(const std::string& auth_token) {
fetcher_->Start();
}
+void GaiaAuthFetcher::StartCookieForOAuthCodeExchange(
+ const std::string& session_index) {
+ // Same as the first step of StartCookieForOAuthLoginTokenExchange;
+ StartCookieForOAuthLoginTokenExchange(session_index);
+ fetch_code_only_ = true;
+}
+
void GaiaAuthFetcher::StartCookieForOAuthLoginTokenExchange(
const std::string& session_index) {
DCHECK(!fetch_pending_) << "Tried to fetch two things at once!";
@@ -566,6 +574,7 @@ void GaiaAuthFetcher::StartCookieForOAuthLoginTokenExchange(
net::LOAD_NORMAL,
this));
fetch_pending_ = true;
+ fetch_code_only_ = false;
fetcher_->Start();
}
@@ -817,9 +826,16 @@ void GaiaAuthFetcher::OnClientLoginToOAuth2Fetched(
if (status.is_success() && response_code == net::HTTP_OK) {
std::string auth_code;
ParseClientLoginToOAuth2Response(cookies, &auth_code);
- StartAuthCodeForOAuth2TokenExchange(auth_code);
+ if (fetch_code_only_)
+ consumer_->OnClientOAuthCodeSuccess(auth_code);
+ else
+ StartAuthCodeForOAuth2TokenExchange(auth_code);
} else {
- consumer_->OnClientOAuthFailure(GenerateAuthError(data, status));
+ GoogleServiceAuthError auth_error(GenerateAuthError(data, status));
+ if (fetch_code_only_)
+ consumer_->OnClientOAuthCodeFailure(auth_error);
+ else
+ consumer_->OnClientOAuthFailure(auth_error);
}
}
diff --git a/google_apis/gaia/gaia_auth_fetcher.h b/google_apis/gaia/gaia_auth_fetcher.h
index 0864f18..3dfb4baa 100644
--- a/google_apis/gaia/gaia_auth_fetcher.h
+++ b/google_apis/gaia/gaia_auth_fetcher.h
@@ -107,6 +107,15 @@ class GaiaAuthFetcher : public net::URLFetcherDelegate {
void StartRevokeOAuth2Token(const std::string& auth_token);
// Start a request to exchange the cookies of a signed-in user session
+ // for an OAuth2 authorization code. In the case of a session with
+ // multiple accounts signed in, |session_index| indicate the which of accounts
+ // within the session.
+ //
+ // Either OnClientOAuthCodeSuccess or OnClientOAuthCodeFailure will be
+ // called on the consumer on the original thread.
+ void StartCookieForOAuthCodeExchange(const std::string& session_index);
+
+ // Start a request to exchange the cookies of a signed-in user session
// for an OAuthLogin-scoped oauth2 token. In the case of a session with
// multiple accounts signed in, |session_index| indicate the which of accounts
// within the session.
@@ -374,6 +383,9 @@ class GaiaAuthFetcher : public net::URLFetcherDelegate {
std::string request_body_;
std::string requested_service_; // Currently tracked for IssueAuthToken only.
bool fetch_pending_;
+ // This is to distinguish between the fetch for oauth login token and that for
+ // oauth code.
+ bool fetch_code_only_;
friend class GaiaAuthFetcherTest;
FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, CaptchaParse);
diff --git a/google_apis/gaia/gaia_auth_fetcher_unittest.cc b/google_apis/gaia/gaia_auth_fetcher_unittest.cc
index a12fb97..5bced8c 100644
--- a/google_apis/gaia/gaia_auth_fetcher_unittest.cc
+++ b/google_apis/gaia/gaia_auth_fetcher_unittest.cc
@@ -175,6 +175,8 @@ class MockGaiaConsumer : public GaiaAuthConsumer {
const std::string& token));
MOCK_METHOD1(OnClientOAuthSuccess,
void(const GaiaAuthConsumer::ClientOAuthResult& result));
+ MOCK_METHOD1(OnClientOAuthCodeSuccess,
+ void(const std::string& result));
MOCK_METHOD1(OnMergeSessionSuccess, void(const std::string& data));
MOCK_METHOD1(OnUberAuthTokenSuccess, void(const std::string& data));
MOCK_METHOD1(OnClientLoginFailure,
@@ -183,6 +185,8 @@ class MockGaiaConsumer : public GaiaAuthConsumer {
const GoogleServiceAuthError& error));
MOCK_METHOD1(OnClientOAuthFailure,
void(const GoogleServiceAuthError& error));
+ MOCK_METHOD1(OnClientOAuthCodeFailure,
+ void(const GoogleServiceAuthError& error));
MOCK_METHOD1(OnMergeSessionFailure, void(
const GoogleServiceAuthError& error));
MOCK_METHOD1(OnUberAuthTokenFailure, void(
@@ -660,6 +664,54 @@ TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenOAuth2TokenPairFailure) {
EXPECT_FALSE(auth.HasPendingFetch());
}
+TEST_F(GaiaAuthFetcherTest, OAuthCodeWithCookiesSuccess) {
+ MockGaiaConsumer consumer;
+ EXPECT_CALL(consumer, OnClientOAuthCodeSuccess("test-code")).Times(1);
+
+ net::TestURLFetcherFactory factory;
+ GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext());
+ auth.StartCookieForOAuthCodeExchange("");
+
+ net::TestURLFetcher* fetcher = factory.GetFetcherByID(0);
+ EXPECT_TRUE(NULL != fetcher);
+ EXPECT_EQ(net::LOAD_NORMAL, fetcher->GetLoadFlags());
+ EXPECT_TRUE(auth.HasPendingFetch());
+
+ net::ResponseCookies cookies;
+ cookies.push_back(kGetAuthCodeValidCookie);
+ MockFetcher mock_fetcher(
+ client_login_to_oauth2_source_,
+ net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0),
+ net::HTTP_OK,
+ cookies,
+ std::string(),
+ net::URLFetcher::POST,
+ &auth);
+ auth.OnURLFetchComplete(&mock_fetcher);
+ EXPECT_FALSE(auth.HasPendingFetch());
+}
+
+TEST_F(GaiaAuthFetcherTest, OAuthCodeWithCookiesFailure) {
+ MockGaiaConsumer consumer;
+ EXPECT_CALL(consumer, OnClientOAuthCodeFailure(_)).Times(1);
+
+ GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext());
+ auth.StartCookieForOAuthCodeExchange("");
+
+ EXPECT_TRUE(auth.HasPendingFetch());
+ net::ResponseCookies cookies;
+ MockFetcher mock_fetcher(
+ client_login_to_oauth2_source_,
+ net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0),
+ net::HTTP_FORBIDDEN,
+ cookies,
+ std::string(),
+ net::URLFetcher::POST,
+ &auth);
+ auth.OnURLFetchComplete(&mock_fetcher);
+ EXPECT_FALSE(auth.HasPendingFetch());
+}
+
TEST_F(GaiaAuthFetcherTest, MergeSessionSuccess) {
MockGaiaConsumer consumer;
EXPECT_CALL(consumer, OnMergeSessionSuccess("<html></html>"))