diff options
author | rickcam@chromium.org <rickcam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-03 21:58:51 +0000 |
---|---|---|
committer | rickcam@chromium.org <rickcam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-03 21:58:51 +0000 |
commit | d912daad6fad6b47e6e3a392545db9de9b66be34 (patch) | |
tree | d2aeec2185c514d7295fc2050933364424ef4c93 /chrome | |
parent | de26b3c9a3bf2b88e1cdc69a172753cad7826064 (diff) | |
download | chromium_src-d912daad6fad6b47e6e3a392545db9de9b66be34.zip chromium_src-d912daad6fad6b47e6e3a392545db9de9b66be34.tar.gz chromium_src-d912daad6fad6b47e6e3a392545db9de9b66be34.tar.bz2 |
Adding service_name to GaiaOAuthFetcher
BUG=91434
TEST=unit tests
Review URL: http://codereview.chromium.org/7551026
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@95333 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/chromeos/login/login_utils.cc | 5 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/online_attempt.cc | 1 | ||||
-rw-r--r-- | chrome/browser/net/gaia/gaia_oauth_consumer.h | 3 | ||||
-rw-r--r-- | chrome/browser/net/gaia/gaia_oauth_fetcher.cc | 19 | ||||
-rw-r--r-- | chrome/browser/net/gaia/gaia_oauth_fetcher.h | 12 | ||||
-rw-r--r-- | chrome/browser/net/gaia/gaia_oauth_fetcher_unittest.cc | 104 | ||||
-rw-r--r-- | chrome/browser/sync/signin_manager.cc | 4 | ||||
-rw-r--r-- | chrome/browser/sync/signin_manager.h | 3 |
8 files changed, 91 insertions, 60 deletions
diff --git a/chrome/browser/chromeos/login/login_utils.cc b/chrome/browser/chromeos/login/login_utils.cc index 9db001e..b07b0e6d 100644 --- a/chrome/browser/chromeos/login/login_utils.cc +++ b/chrome/browser/chromeos/login/login_utils.cc @@ -156,6 +156,7 @@ class OAuthLoginVerifier : public GaiaOAuthConsumer { : oauth_fetcher_(this, user_profile->GetOffTheRecordProfile()->GetRequestContext(), user_profile->GetOffTheRecordProfile(), + GaiaConstants::kSyncService, kServiceScopeChromeOS), oauth1_token_(oauth1_token), oauth1_secret_(oauth1_secret) { @@ -200,6 +201,7 @@ class PolicyOAuthFetcher : public GaiaOAuthConsumer { : oauth_fetcher_(this, profile->GetRequestContext(), profile, + GaiaConstants::kDeviceManagementService, kServiceScopeChromeOSDeviceManagement), oauth1_token_(oauth1_token), oauth1_secret_(oauth1_secret) { @@ -210,11 +212,13 @@ class PolicyOAuthFetcher : public GaiaOAuthConsumer { void Start() { oauth_fetcher_.StartOAuthWrapBridge(oauth1_token_, oauth1_secret_, "3600", + std::string(GaiaConstants::kDeviceManagementService), std::string(kServiceScopeChromeOSDeviceManagement)); } // GaiaOAuthConsumer implementation: virtual void OnOAuthWrapBridgeSuccess( + const std::string& service_name, const std::string& token, const std::string& expires_in) OVERRIDE { policy::BrowserPolicyConnector* browser_policy_connector = @@ -565,6 +569,7 @@ void LoginUtilsImpl::FetchOAuth1AccessToken(Profile* auth_profile) { oauth_fetcher_.reset(new GaiaOAuthFetcher(this, auth_profile->GetRequestContext(), auth_profile, + GaiaConstants::kSyncService, kServiceScopeChromeOS)); // Let's first get the Oauth request token and OAuth1 token+secret. // One we get that, we will kick off individial requests for OAuth2 tokens for diff --git a/chrome/browser/chromeos/login/online_attempt.cc b/chrome/browser/chromeos/login/online_attempt.cc index f364eaf..1936e9d 100644 --- a/chrome/browser/chromeos/login/online_attempt.cc +++ b/chrome/browser/chromeos/login/online_attempt.cc @@ -63,6 +63,7 @@ void OnlineAttempt::Initiate(Profile* auth_profile) { new GaiaOAuthFetcher(this, auth_profile->GetRequestContext(), auth_profile, + GaiaConstants::kSyncService, kServiceScopeChromeOS)); } else { client_fetcher_.reset( diff --git a/chrome/browser/net/gaia/gaia_oauth_consumer.h b/chrome/browser/net/gaia/gaia_oauth_consumer.h index 0865063..bee7840 100644 --- a/chrome/browser/net/gaia/gaia_oauth_consumer.h +++ b/chrome/browser/net/gaia/gaia_oauth_consumer.h @@ -24,7 +24,8 @@ class GaiaOAuthConsumer { virtual void OnOAuthGetAccessTokenFailure( const GoogleServiceAuthError& error) {} - virtual void OnOAuthWrapBridgeSuccess(const std::string& token, + virtual void OnOAuthWrapBridgeSuccess(const std::string& service_name, + const std::string& token, const std::string& expires_in) {} virtual void OnOAuthWrapBridgeFailure(const GoogleServiceAuthError& error) {} diff --git a/chrome/browser/net/gaia/gaia_oauth_fetcher.cc b/chrome/browser/net/gaia/gaia_oauth_fetcher.cc index 882ff69..243f193 100644 --- a/chrome/browser/net/gaia/gaia_oauth_fetcher.cc +++ b/chrome/browser/net/gaia/gaia_oauth_fetcher.cc @@ -54,12 +54,14 @@ static const char kOAuthTokenCookie[] = "oauth_token"; GaiaOAuthFetcher::GaiaOAuthFetcher(GaiaOAuthConsumer* consumer, net::URLRequestContextGetter* getter, Profile* profile, + const std::string& service_name, const std::string& service_scope) : consumer_(consumer), getter_(getter), profile_(profile), - service_scope_(service_scope), popup_(NULL), + service_name_(service_name), + service_scope_(service_scope), fetch_pending_(false), auto_fetch_limit_(ALL_OAUTH_STEPS) {} @@ -203,6 +205,7 @@ void GaiaOAuthFetcher::ParseGetOAuthTokenResponse( } } } + // Helper method that extracts tokens from a successful reply. // static void GaiaOAuthFetcher::ParseOAuthLoginResponse( @@ -405,18 +408,21 @@ void GaiaOAuthFetcher::StartOAuthWrapBridge( const std::string& oauth1_access_token, const std::string& oauth1_access_token_secret, const std::string& wrap_token_duration, - const std::string& oauth2_scope) { + const std::string& service_name, + const std::string& service_scope) { DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; - std::string combined_oauth2_scope = oauth2_scope + " " + + VLOG(1) << "Starting OAuthWrapBridge for: " << service_name; + std::string combined_scope = service_scope + " " + kOAuthWrapBridgeUserInfoScope; + service_name_ = service_name; // Must outlive fetcher_. request_body_ = MakeOAuthWrapBridgeBody( oauth1_access_token, oauth1_access_token_secret, wrap_token_duration, - combined_oauth2_scope); + combined_scope); request_headers_ = ""; fetcher_.reset(CreateGaiaFetcher(getter_, @@ -588,7 +594,8 @@ void GaiaOAuthFetcher::OnOAuthGetAccessTokenFetched( ParseOAuthGetAccessTokenResponse(data, &token, &secret); consumer_->OnOAuthGetAccessTokenSuccess(token, secret); if (ShouldAutoFetch(OAUTH2_SERVICE_ACCESS_TOKEN)) - StartOAuthWrapBridge(token, secret, "3600", service_scope_); + StartOAuthWrapBridge( + token, secret, "3600", service_name_, service_scope_); } else { consumer_->OnOAuthGetAccessTokenFailure(GenerateAuthError(data, status)); } @@ -603,7 +610,7 @@ void GaiaOAuthFetcher::OnOAuthWrapBridgeFetched( std::string token; std::string expires_in; ParseOAuthWrapBridgeResponse(data, &token, &expires_in); - consumer_->OnOAuthWrapBridgeSuccess(token, expires_in); + consumer_->OnOAuthWrapBridgeSuccess(service_name_, token, expires_in); if (ShouldAutoFetch(USER_INFO)) StartUserInfo(token); } else { diff --git a/chrome/browser/net/gaia/gaia_oauth_fetcher.h b/chrome/browser/net/gaia/gaia_oauth_fetcher.h index 4a635ce..be2bea8 100644 --- a/chrome/browser/net/gaia/gaia_oauth_fetcher.h +++ b/chrome/browser/net/gaia/gaia_oauth_fetcher.h @@ -53,6 +53,7 @@ class GaiaOAuthFetcher : public URLFetcher::Delegate, GaiaOAuthFetcher(GaiaOAuthConsumer* consumer, net::URLRequestContextGetter* getter, Profile* profile, + const std::string& service_name, const std::string& service_scope); virtual ~GaiaOAuthFetcher(); @@ -92,13 +93,15 @@ class GaiaOAuthFetcher : public URLFetcher::Delegate, // wrap_token_duration is typically one hour, // which is also the max -- you can only decrease it. // - // oauth2_scope should be specific to a service. For example, Chromium Sync - // uses https://www.googleapis.com/auth/chromesync as it's OAuth2 scope. + // service_name and service_scope should be specific to a service. For + // example, Chromium Sync uses https://www.googleapis.com/auth/chromesync as + // its OAuth2 service scope. virtual void StartOAuthWrapBridge( const std::string& oauth1_access_token, const std::string& oauth1_access_token_secret, const std::string& wrap_token_duration, - const std::string& oauth2_scope); + const std::string& service_name, + const std::string& service_scope); // Obtains user information related to an OAuth2 access token // @@ -230,7 +233,6 @@ class GaiaOAuthFetcher : public URLFetcher::Delegate, GaiaOAuthConsumer* const consumer_; net::URLRequestContextGetter* const getter_; Profile* profile_; - std::string service_scope_; Browser* popup_; NotificationRegistrar registrar_; @@ -238,6 +240,8 @@ class GaiaOAuthFetcher : public URLFetcher::Delegate, scoped_ptr<URLFetcher> fetcher_; std::string request_body_; std::string request_headers_; + std::string service_name_; + std::string service_scope_; bool fetch_pending_; AutoFetchLimit auto_fetch_limit_; diff --git a/chrome/browser/net/gaia/gaia_oauth_fetcher_unittest.cc b/chrome/browser/net/gaia/gaia_oauth_fetcher_unittest.cc index 89fb650..24b9db4 100644 --- a/chrome/browser/net/gaia/gaia_oauth_fetcher_unittest.cc +++ b/chrome/browser/net/gaia/gaia_oauth_fetcher_unittest.cc @@ -13,6 +13,7 @@ #include "chrome/browser/net/gaia/gaia_oauth_consumer.h" #include "chrome/browser/net/gaia/gaia_oauth_fetcher.h" #include "chrome/common/chrome_notification_types.h" +#include "chrome/common/net/gaia/gaia_constants.h" #include "chrome/common/net/gaia/google_service_auth_error.h" #include "chrome/common/net/http_return.h" #include "chrome/test/base/testing_profile.h" @@ -62,8 +63,9 @@ class MockGaiaOAuthConsumer : public GaiaOAuthConsumer { MOCK_METHOD1(OnOAuthGetAccessTokenFailure, void(const GoogleServiceAuthError& error)); - MOCK_METHOD2(OnOAuthWrapBridgeSuccess, - void(const std::string& token, + MOCK_METHOD3(OnOAuthWrapBridgeSuccess, + void(const std::string& service_name, + const std::string& token, const std::string& expires_in)); MOCK_METHOD1(OnOAuthWrapBridgeFailure, void(const GoogleServiceAuthError& error)); @@ -77,18 +79,21 @@ class MockGaiaOAuthFetcher : public GaiaOAuthFetcher { MockGaiaOAuthFetcher(GaiaOAuthConsumer* consumer, net::URLRequestContextGetter* getter, Profile* profile, + const std::string& service_name, const std::string& service_scope) - : GaiaOAuthFetcher(consumer, getter, profile, service_scope) {} + : GaiaOAuthFetcher( + consumer, getter, profile, service_name, service_scope) {} ~MockGaiaOAuthFetcher() {} MOCK_METHOD1(StartOAuthGetAccessToken, void(const std::string& oauth1_request_token)); - MOCK_METHOD4(StartOAuthWrapBridge, + MOCK_METHOD5(StartOAuthWrapBridge, void(const std::string& oauth1_access_token, const std::string& oauth1_access_token_secret, const std::string& wrap_token_duration, + const std::string& service_name, const std::string& oauth2_scope)); MOCK_METHOD1(StartUserInfo, void(const std::string& oauth2_access_token)); @@ -129,13 +134,13 @@ TEST(GaiaOAuthFetcherTest, GetOAuthToken) { TestingProfile profile; - MockGaiaOAuthFetcher auth(&consumer, - profile.GetRequestContext(), - &profile, - std::string()); - EXPECT_CALL(auth, StartOAuthGetAccessToken(oauth_token)).Times(1); + MockGaiaOAuthFetcher oauth_fetcher(&consumer, + profile.GetRequestContext(), + &profile, + std::string()); + EXPECT_CALL(oauth_fetcher, StartOAuthGetAccessToken(oauth_token)).Times(1); - auth.Observe( + oauth_fetcher.Observe( chrome::NOTIFICATION_COOKIE_CHANGED, Source<Profile>(&profile), Details<ChromeCookieDetails>(cookie_details.get())); @@ -156,23 +161,26 @@ TEST(GaiaOAuthFetcherTest, OAuthGetAccessToken) { oauth_token_secret)).Times(1); TestingProfile profile; - MockGaiaOAuthFetcher auth(&consumer, - profile .GetRequestContext(), - &profile, - std::string()); - EXPECT_CALL(auth, StartOAuthWrapBridge(oauth_token, - oauth_token_secret, - "3600", - _)).Times(1); + MockGaiaOAuthFetcher oauth_fetcher(&consumer, + profile.GetRequestContext(), + &profile, + "service_name-eKARPyky", + "service_scope-JnG18MEE"); + EXPECT_CALL(oauth_fetcher, + StartOAuthWrapBridge(oauth_token, + oauth_token_secret, + "3600", + "service_name-eKARPyky", + "service_scope-JnG18MEE")).Times(1); net::ResponseCookies cookies; net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); - auth.OnURLFetchComplete(NULL, - GURL(kOAuthGetAccessTokenUrl), - status, - RC_REQUEST_OK, - cookies, - data); + oauth_fetcher.OnURLFetchComplete(NULL, + GURL(kOAuthGetAccessTokenUrl), + status, + RC_REQUEST_OK, + cookies, + data); } TEST(GaiaOAuthFetcherTest, OAuthWrapBridge) { @@ -185,31 +193,32 @@ TEST(GaiaOAuthFetcherTest, OAuthWrapBridge) { MockGaiaOAuthConsumer consumer; EXPECT_CALL(consumer, - OnOAuthWrapBridgeSuccess(wrap_token, + OnOAuthWrapBridgeSuccess("service_name-62Ykg3K1", + wrap_token, expires_in)).Times(1); TestingProfile profile; - MockGaiaOAuthFetcher auth(&consumer, - profile .GetRequestContext(), - &profile, - std::string()); - EXPECT_CALL(auth, StartUserInfo(wrap_token)).Times(1); + MockGaiaOAuthFetcher oauth_fetcher(&consumer, + profile .GetRequestContext(), + &profile, + "service_name-62Ykg3K1", + "service_scope-0fL85iOi"); + EXPECT_CALL(oauth_fetcher, StartUserInfo(wrap_token)).Times(1); net::ResponseCookies cookies; net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); - auth.OnURLFetchComplete(NULL, - GURL(kOAuthWrapBridgeUrl), - status, - RC_REQUEST_OK, - cookies, - data); + oauth_fetcher.OnURLFetchComplete(NULL, + GURL(kOAuthWrapBridgeUrl), + status, + RC_REQUEST_OK, + cookies, + data); } TEST(GaiaOAuthFetcherTest, UserInfo) { const std::string email_address="someone@somewhere.net"; const std::string wrap_token="1/OAuth2-Access_Token-nopqrstuvwxyz1234567890"; const std::string expires_in="3600"; - const std::string data("{\n \"email\": \"someone@somewhere.net\",\n" " \"verified_email\": true\n}\n"); MockGaiaOAuthConsumer consumer; @@ -217,17 +226,18 @@ TEST(GaiaOAuthFetcherTest, UserInfo) { OnUserInfoSuccess(email_address)).Times(1); TestingProfile profile; - MockGaiaOAuthFetcher auth(&consumer, - profile .GetRequestContext(), - &profile, - std::string()); + MockGaiaOAuthFetcher oauth_fetcher(&consumer, + profile .GetRequestContext(), + &profile, + "service_name-S2igVNUm", + "service_scope-Nrj4LmgU"); net::ResponseCookies cookies; net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); - auth.OnURLFetchComplete(NULL, - GURL(kUserInfoUrl), - status, - RC_REQUEST_OK, - cookies, - data); + oauth_fetcher.OnURLFetchComplete(NULL, + GURL(kUserInfoUrl), + status, + RC_REQUEST_OK, + cookies, + data); } diff --git a/chrome/browser/sync/signin_manager.cc b/chrome/browser/sync/signin_manager.cc index 2c06078..bdccf86 100644 --- a/chrome/browser/sync/signin_manager.cc +++ b/chrome/browser/sync/signin_manager.cc @@ -84,6 +84,7 @@ void SigninManager::StartOAuthSignIn() { oauth_login_.reset(new GaiaOAuthFetcher(this, profile_->GetRequestContext(), profile_, + GaiaConstants::kSyncService, kSyncOAuth2Scope)); oauth_login_->StartGetOAuthToken(); } @@ -237,7 +238,8 @@ void SigninManager::OnOAuthGetAccessTokenFailure( VLOG(1) << "SigninManager::OnOAuthGetAccessTokenFailure"; } -void SigninManager::OnOAuthWrapBridgeSuccess(const std::string& token, +void SigninManager::OnOAuthWrapBridgeSuccess(const std::string& service_name, + const std::string& token, const std::string& expires_in) { VLOG(1) << "SigninManager::OnOAuthWrapBridgeSuccess"; } diff --git a/chrome/browser/sync/signin_manager.h b/chrome/browser/sync/signin_manager.h index 60d0320..d2140819 100644 --- a/chrome/browser/sync/signin_manager.h +++ b/chrome/browser/sync/signin_manager.h @@ -100,7 +100,8 @@ class SigninManager : public GaiaAuthConsumer, const std::string& secret) OVERRIDE; virtual void OnOAuthGetAccessTokenFailure( const GoogleServiceAuthError& error) OVERRIDE; - virtual void OnOAuthWrapBridgeSuccess(const std::string& token, + virtual void OnOAuthWrapBridgeSuccess(const std::string& service_name, + const std::string& token, const std::string& expires_in) OVERRIDE; virtual void OnOAuthWrapBridgeFailure(const GoogleServiceAuthError& error); |