diff options
author | pavely@chromium.org <pavely@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-13 23:24:47 +0000 |
---|---|---|
committer | pavely@chromium.org <pavely@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-13 23:24:47 +0000 |
commit | 2558134cb64e8639d36b83b2ba55b641471dcc0a (patch) | |
tree | a68d9238f96b79fe070af5ed8136f09d7e5f2873 /google_apis | |
parent | c2ef3ebaeb1dd0526efb95064842480867423fe7 (diff) | |
download | chromium_src-2558134cb64e8639d36b83b2ba55b641471dcc0a.zip chromium_src-2558134cb64e8639d36b83b2ba55b641471dcc0a.tar.gz chromium_src-2558134cb64e8639d36b83b2ba55b641471dcc0a.tar.bz2 |
Pass device_id and device_type to programmatic_auth endpoint when requesting LST
I added StartCookieForOAuthLoginTokenExchangeWithDeviceId, it is not used anywhere.
I'll add code that uses it in the future changes.
BUG=382968
R=rogerta@chromium.org
Review URL: https://codereview.chromium.org/329583002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@277128 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'google_apis')
-rw-r--r-- | google_apis/gaia/gaia_auth_fetcher.cc | 38 | ||||
-rw-r--r-- | google_apis/gaia/gaia_auth_fetcher.h | 19 | ||||
-rw-r--r-- | google_apis/gaia/gaia_auth_fetcher_unittest.cc | 19 |
3 files changed, 68 insertions, 8 deletions
diff --git a/google_apis/gaia/gaia_auth_fetcher.cc b/google_apis/gaia/gaia_auth_fetcher.cc index f0494ab..ca4cdc0 100644 --- a/google_apis/gaia/gaia_auth_fetcher.cc +++ b/google_apis/gaia/gaia_auth_fetcher.cc @@ -88,6 +88,9 @@ const char GaiaAuthFetcher::kIssueAuthTokenFormat[] = const char GaiaAuthFetcher::kClientLoginToOAuth2BodyFormat[] = "scope=%s&client_id=%s"; // static +const char GaiaAuthFetcher::kClientLoginToOAuth2WithDeviceTypeBodyFormat[] = + "scope=%s&client_id=%s&device_type=chrome"; +// static const char GaiaAuthFetcher::kOAuth2CodeToTokenPairBodyFormat[] = "scope=%s&" "grant_type=authorization_code&" @@ -154,6 +157,8 @@ const char GaiaAuthFetcher::kOAuthHeaderFormat[] = "Authorization: OAuth %s"; const char GaiaAuthFetcher::kOAuth2BearerHeaderFormat[] = "Authorization: Bearer %s"; // static +const char GaiaAuthFetcher::kDeviceIdHeaderFormat[] = "X-Device-ID: %s"; +// static const char GaiaAuthFetcher::kClientLoginToOAuth2CookiePartSecure[] = "secure"; // static const char GaiaAuthFetcher::kClientLoginToOAuth2CookiePartHttpOnly[] = @@ -296,14 +301,20 @@ std::string GaiaAuthFetcher::MakeIssueAuthTokenBody( } // static -std::string GaiaAuthFetcher::MakeGetAuthCodeBody() { +std::string GaiaAuthFetcher::MakeGetAuthCodeBody(bool include_device_type) { std::string encoded_scope = net::EscapeUrlEncodedData( GaiaConstants::kOAuth1LoginScope, true); std::string encoded_client_id = net::EscapeUrlEncodedData( GaiaUrls::GetInstance()->oauth2_chrome_client_id(), true); - return base::StringPrintf(kClientLoginToOAuth2BodyFormat, - encoded_scope.c_str(), - encoded_client_id.c_str()); + if (include_device_type) { + return base::StringPrintf(kClientLoginToOAuth2WithDeviceTypeBodyFormat, + encoded_scope.c_str(), + encoded_client_id.c_str()); + } else { + return base::StringPrintf(kClientLoginToOAuth2BodyFormat, + encoded_scope.c_str(), + encoded_client_id.c_str()); + } } // static @@ -514,7 +525,7 @@ void GaiaAuthFetcher::StartLsoForOAuthLoginTokenExchange( DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; DVLOG(1) << "Starting OAuth login token exchange with auth_token"; - request_body_ = MakeGetAuthCodeBody(); + request_body_ = MakeGetAuthCodeBody(false); client_login_to_oauth2_gurl_ = GaiaUrls::GetInstance()->client_login_to_oauth2_url(); @@ -545,10 +556,17 @@ void GaiaAuthFetcher::StartRevokeOAuth2Token(const std::string& auth_token) { void GaiaAuthFetcher::StartCookieForOAuthLoginTokenExchange( const std::string& session_index) { + StartCookieForOAuthLoginTokenExchangeWithDeviceId(session_index, + std::string()); +} + +void GaiaAuthFetcher::StartCookieForOAuthLoginTokenExchangeWithDeviceId( + const std::string& session_index, + const std::string& device_id) { DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; DVLOG(1) << "Starting OAuth login token fetch with cookie jar"; - request_body_ = MakeGetAuthCodeBody(); + request_body_ = MakeGetAuthCodeBody(!device_id.empty()); client_login_to_oauth2_gurl_ = GaiaUrls::GetInstance()->client_login_to_oauth2_url(); @@ -557,9 +575,15 @@ void GaiaAuthFetcher::StartCookieForOAuthLoginTokenExchange( client_login_to_oauth2_gurl_.Resolve("?authuser=" + session_index); } + std::string device_id_header; + if (!device_id.empty()) { + device_id_header = + base::StringPrintf(kDeviceIdHeaderFormat, device_id.c_str()); + } + fetcher_.reset(CreateGaiaFetcher(getter_, request_body_, - std::string(), + device_id_header, client_login_to_oauth2_gurl_, net::LOAD_NORMAL, this)); diff --git a/google_apis/gaia/gaia_auth_fetcher.h b/google_apis/gaia/gaia_auth_fetcher.h index 0864f18..aa66a49 100644 --- a/google_apis/gaia/gaia_auth_fetcher.h +++ b/google_apis/gaia/gaia_auth_fetcher.h @@ -115,6 +115,19 @@ class GaiaAuthFetcher : public net::URLFetcherDelegate { // called on the consumer on the original thread. void StartCookieForOAuthLoginTokenExchange(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. + // Resulting refresh token is annotated on the server with |device_id|. Format + // of device_id on the server is at most 64 unicode characters. + // + // Either OnClientOAuthSuccess or OnClientOAuthFailure will be + // called on the consumer on the original thread. + void StartCookieForOAuthLoginTokenExchangeWithDeviceId( + const std::string& session_index, + const std::string& device_id); + // Start a request to exchange the authorization code for an OAuthLogin-scoped // oauth2 token. // @@ -191,6 +204,9 @@ class GaiaAuthFetcher : public net::URLFetcherDelegate { static const char kIssueAuthTokenFormat[]; // The format of the POST body to get OAuth2 auth code from auth token. static const char kClientLoginToOAuth2BodyFormat[]; + // The format of the POST body to get OAuth2 auth code from auth token. This + // format is used for request annotated with device_id. + static const char kClientLoginToOAuth2WithDeviceTypeBodyFormat[]; // The format of the POST body to get OAuth2 token pair from auth code. static const char kOAuth2CodeToTokenPairBodyFormat[]; // The format of the POST body to revoke an OAuth2 token. @@ -229,6 +245,7 @@ class GaiaAuthFetcher : public net::URLFetcherDelegate { static const char kAuthHeaderFormat[]; static const char kOAuthHeaderFormat[]; static const char kOAuth2BearerHeaderFormat[]; + static const char kDeviceIdHeaderFormat[]; static const char kClientLoginToOAuth2CookiePartSecure[]; static const char kClientLoginToOAuth2CookiePartHttpOnly[]; static const char kClientLoginToOAuth2CookiePartCodePrefix[]; @@ -314,7 +331,7 @@ class GaiaAuthFetcher : public net::URLFetcherDelegate { const std::string& lsid, const char* const service); // Create body to get OAuth2 auth code. - static std::string MakeGetAuthCodeBody(); + static std::string MakeGetAuthCodeBody(bool include_device_type); // Given auth code, create body to get OAuth2 token pair. static std::string MakeGetTokenPairBody(const std::string& auth_code); // Given an OAuth2 token, create body to revoke the token. diff --git a/google_apis/gaia/gaia_auth_fetcher_unittest.cc b/google_apis/gaia/gaia_auth_fetcher_unittest.cc index af235df..75a8db7 100644 --- a/google_apis/gaia/gaia_auth_fetcher_unittest.cc +++ b/google_apis/gaia/gaia_auth_fetcher_unittest.cc @@ -569,6 +569,25 @@ TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenWithCookies) { net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); EXPECT_TRUE(NULL != fetcher); EXPECT_EQ(net::LOAD_NORMAL, fetcher->GetLoadFlags()); + EXPECT_FALSE(EndsWith(fetcher->upload_data(), "device_type=chrome", true)); +} + +TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenWithCookies_DeviceId) { + MockGaiaConsumer consumer; + net::TestURLFetcherFactory factory; + std::string expected_device_id("ABCDE-12345"); + GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); + auth.StartCookieForOAuthLoginTokenExchangeWithDeviceId("0", + expected_device_id); + net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); + EXPECT_TRUE(NULL != fetcher); + EXPECT_EQ(net::LOAD_NORMAL, fetcher->GetLoadFlags()); + EXPECT_TRUE(EndsWith(fetcher->upload_data(), "device_type=chrome", true)); + net::HttpRequestHeaders extra_request_headers; + fetcher->GetExtraRequestHeaders(&extra_request_headers); + std::string device_id; + EXPECT_TRUE(extra_request_headers.GetHeader("X-Device-ID", &device_id)); + EXPECT_EQ(device_id, expected_device_id); } TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenClientLoginToOAuth2Failure) { |