diff options
author | antrim <antrim@chromium.org> | 2015-03-11 14:44:57 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-03-11 21:45:41 +0000 |
commit | 5a734aca8aec0dffbce8361fe883edd15c8e3fbd (patch) | |
tree | 9f614142dc9d68cfa629ef72b1e77cf7b1ffa854 /google_apis | |
parent | cbcc6e00154f90423de5003076e31829adb8002f (diff) | |
download | chromium_src-5a734aca8aec0dffbce8361fe883edd15c8e3fbd.zip chromium_src-5a734aca8aec0dffbce8361fe883edd15c8e3fbd.tar.gz chromium_src-5a734aca8aec0dffbce8361fe883edd15c8e3fbd.tar.bz2 |
Add tokeninfo call with token identified by token_handle parameter.
See go/external-token-handle for details.
BUG=462445
R=rogerta@chromium.org
Review URL: https://codereview.chromium.org/993103002
Cr-Commit-Position: refs/heads/master@{#320151}
Diffstat (limited to 'google_apis')
-rw-r--r-- | google_apis/gaia/gaia_oauth_client.cc | 18 | ||||
-rw-r--r-- | google_apis/gaia/gaia_oauth_client.h | 8 | ||||
-rw-r--r-- | google_apis/gaia/gaia_oauth_client_unittest.cc | 30 |
3 files changed, 49 insertions, 7 deletions
diff --git a/google_apis/gaia/gaia_oauth_client.cc b/google_apis/gaia/gaia_oauth_client.cc index 56647f4..adb8c6f 100644 --- a/google_apis/gaia/gaia_oauth_client.cc +++ b/google_apis/gaia/gaia_oauth_client.cc @@ -59,7 +59,8 @@ class GaiaOAuthClient::Core void GetUserInfo(const std::string& oauth_access_token, int max_retries, Delegate* delegate); - void GetTokenInfo(const std::string& oauth_access_token, + void GetTokenInfo(const std::string& qualifier, + const std::string& query, int max_retries, Delegate* delegate); @@ -189,14 +190,15 @@ void GaiaOAuthClient::Core::GetUserInfoImpl( request_->Start(); } -void GaiaOAuthClient::Core::GetTokenInfo(const std::string& oauth_access_token, +void GaiaOAuthClient::Core::GetTokenInfo(const std::string& qualifier, + const std::string& query, int max_retries, Delegate* delegate) { DCHECK_EQ(request_type_, NO_PENDING_REQUEST); DCHECK(!request_.get()); request_type_ = TOKEN_INFO; std::string post_body = - "access_token=" + net::EscapeUrlEncodedData(oauth_access_token, true); + qualifier + "=" + net::EscapeUrlEncodedData(query, true); MakeGaiaRequest(GURL(GaiaUrls::GetInstance()->oauth2_token_info_url()), post_body, max_retries, @@ -396,7 +398,15 @@ void GaiaOAuthClient::GetUserInfo(const std::string& access_token, void GaiaOAuthClient::GetTokenInfo(const std::string& access_token, int max_retries, Delegate* delegate) { - return core_->GetTokenInfo(access_token, max_retries, delegate); + return core_->GetTokenInfo("access_token", access_token, max_retries, + delegate); +} + +void GaiaOAuthClient::GetTokenHandleInfo(const std::string& token_handle, + int max_retries, + Delegate* delegate) { + return core_->GetTokenInfo("token_handle", token_handle, max_retries, + delegate); } } // namespace gaia diff --git a/google_apis/gaia/gaia_oauth_client.h b/google_apis/gaia/gaia_oauth_client.h index 68eb766..e3ecd0d 100644 --- a/google_apis/gaia/gaia_oauth_client.h +++ b/google_apis/gaia/gaia_oauth_client.h @@ -128,6 +128,14 @@ class GaiaOAuthClient { int max_retries, Delegate* delegate); + // Call the tokeninfo API for given |token_handle|, returning a dictionary of + // response values. Basic results will be returned via + // |OnGetTokenInfoResponse| call: audience, expires_in, user_id. See + // |max_retries| docs above. + void GetTokenHandleInfo(const std::string& token_handle, + int max_retries, + Delegate* delegate); + private: // The guts of the implementation live in this class. class Core; diff --git a/google_apis/gaia/gaia_oauth_client_unittest.cc b/google_apis/gaia/gaia_oauth_client_unittest.cc index a828beb..6197b89 100644 --- a/google_apis/gaia/gaia_oauth_client_unittest.cc +++ b/google_apis/gaia/gaia_oauth_client_unittest.cc @@ -127,6 +127,7 @@ class MockOAuthFetcherFactory : public net::URLFetcherFactory, }; const std::string kTestAccessToken = "1/fFAGRNJru1FTz70BzhT3Zg"; +const std::string kTestAccessTokenHandle = "1/kjhH87dfgkj87Hhj5KJkjZ"; const std::string kTestRefreshToken = "1/6BMfW9j53gdGImsixUH6kU5RsR4zwI9lUVX-tqf8JXQ"; const std::string kTestUserEmail = "a_user@gmail.com"; @@ -165,7 +166,12 @@ const std::string kDummyTokenInfoResult = "\"audience\": \"1234567890.apps.googleusercontent.com\"," "\"scope\": \"https://googleapis.com/oauth2/v2/tokeninfo\"," "\"expires_in\":" + base::IntToString(kTestExpiresIn) + "}"; -} + +const std::string kDummyTokenHandleInfoResult = + "{\"audience\": \"1234567890.apps.googleusercontent.com\"," + "\"expires_in\":" + base::IntToString(kTestExpiresIn) + "}"; + +} // namespace namespace gaia { @@ -381,11 +387,29 @@ TEST_F(GaiaOAuthClientTest, GetTokenInfo) { factory.set_results(kDummyTokenInfoResult); GaiaOAuthClient auth(GetRequestContext()); - auth.GetTokenInfo("access_token", 1, &delegate); + auth.GetTokenInfo("some_token", 1, &delegate); std::string issued_to; - ASSERT_TRUE(captured_result->GetString("issued_to", &issued_to)); + ASSERT_TRUE(captured_result->GetString("issued_to", &issued_to)); ASSERT_EQ("1234567890.apps.googleusercontent.com", issued_to); } +TEST_F(GaiaOAuthClientTest, GetTokenHandleInfo) { + const base::DictionaryValue* captured_result; + + MockGaiaOAuthClientDelegate delegate; + EXPECT_CALL(delegate, OnGetTokenInfoResponsePtr(_)) + .WillOnce(SaveArg<0>(&captured_result)); + + MockOAuthFetcherFactory factory; + factory.set_results(kDummyTokenHandleInfoResult); + + GaiaOAuthClient auth(GetRequestContext()); + auth.GetTokenHandleInfo("some_handle", 1, &delegate); + + std::string audience; + ASSERT_TRUE(captured_result->GetString("audience", &audience)); + ASSERT_EQ("1234567890.apps.googleusercontent.com", audience); +} + } // namespace gaia |