summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authormunjal@chromium.org <munjal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-29 04:47:17 +0000
committermunjal@chromium.org <munjal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-29 04:47:17 +0000
commit18c69d7a46962952cec1aed4450363c7ad00ab13 (patch)
treeb050d79552e92db27d11e5bb0f727fedb46c123b /chrome
parent7ee9fa600b755946e87ce8f269728c57a0a943e4 (diff)
downloadchromium_src-18c69d7a46962952cec1aed4450363c7ad00ab13.zip
chromium_src-18c69d7a46962952cec1aed4450363c7ad00ab13.tar.gz
chromium_src-18c69d7a46962952cec1aed4450363c7ad00ab13.tar.bz2
Make the access token fetcher class more generic (takes in client id and client secret)
so that it can be used to refresh any OAuth2 access token, not just the login scoped token. Review URL: http://codereview.chromium.org/8720001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111869 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/common/net/gaia/oauth2_access_token_fetcher.cc17
-rw-r--r--chrome/common/net/gaia/oauth2_access_token_fetcher.h12
-rw-r--r--chrome/common/net/gaia/oauth2_access_token_fetcher_unittest.cc6
3 files changed, 23 insertions, 12 deletions
diff --git a/chrome/common/net/gaia/oauth2_access_token_fetcher.cc b/chrome/common/net/gaia/oauth2_access_token_fetcher.cc
index 7f4e256b07..d83135f 100644
--- a/chrome/common/net/gaia/oauth2_access_token_fetcher.cc
+++ b/chrome/common/net/gaia/oauth2_access_token_fetcher.cc
@@ -94,7 +94,11 @@ void OAuth2AccessTokenFetcher::CancelRequest() {
fetcher_.reset();
}
-void OAuth2AccessTokenFetcher::Start(const std::string& refresh_token) {
+void OAuth2AccessTokenFetcher::Start(const std::string& client_id,
+ const std::string& client_secret,
+ const std::string& refresh_token) {
+ client_id_ = client_id;
+ client_secret_ = client_secret;
refresh_token_ = refresh_token;
StartGetAccessToken();
}
@@ -105,7 +109,7 @@ void OAuth2AccessTokenFetcher::StartGetAccessToken() {
fetcher_.reset(CreateFetcher(
getter_,
MakeGetAccessTokenUrl(),
- MakeGetAccessTokenBody(refresh_token_),
+ MakeGetAccessTokenBody(client_id_, client_secret_, refresh_token_),
this));
fetcher_->Start(); // OnURLFetchComplete will be called.
}
@@ -156,14 +160,13 @@ GURL OAuth2AccessTokenFetcher::MakeGetAccessTokenUrl() {
// static
std::string OAuth2AccessTokenFetcher::MakeGetAccessTokenBody(
+ const std::string& client_id,
+ const std::string& client_secret,
const std::string& refresh_token) {
return StringPrintf(
kGetAccessTokenBodyFormat,
- net::EscapeUrlEncodedData(
- GaiaUrls::GetInstance()->oauth2_chrome_client_id(), true).c_str(),
- net::EscapeUrlEncodedData(
- GaiaUrls::GetInstance()->oauth2_chrome_client_secret(),
- true).c_str(),
+ net::EscapeUrlEncodedData(client_id, true).c_str(),
+ net::EscapeUrlEncodedData(client_secret, true).c_str(),
net::EscapeUrlEncodedData(refresh_token, true).c_str());
}
diff --git a/chrome/common/net/gaia/oauth2_access_token_fetcher.h b/chrome/common/net/gaia/oauth2_access_token_fetcher.h
index 5ba4af7..b1d2859 100644
--- a/chrome/common/net/gaia/oauth2_access_token_fetcher.h
+++ b/chrome/common/net/gaia/oauth2_access_token_fetcher.h
@@ -24,6 +24,8 @@ class URLRequestStatus;
// Abstracts the details to get OAuth2 access token token from
// OAuth2 refresh token.
+// See "Using the Refresh Token" section in:
+// http://code.google.com/apis/accounts/docs/OAuth2WebServer.html
//
// This class should be used on a single thread, but it can be whichever thread
// that you like.
@@ -45,7 +47,9 @@ class OAuth2AccessTokenFetcher : public content::URLFetcherDelegate {
const std::string& source);
virtual ~OAuth2AccessTokenFetcher();
- void Start(const std::string& refresh_token);
+ void Start(const std::string& client_id,
+ const std::string& client_secret,
+ const std::string& refresh_token);
void CancelRequest();
@@ -70,7 +74,9 @@ class OAuth2AccessTokenFetcher : public content::URLFetcherDelegate {
// Other helpers.
static GURL MakeGetAccessTokenUrl();
- static std::string MakeGetAccessTokenBody(const std::string& refresh_token);
+ static std::string MakeGetAccessTokenBody(const std::string& client_id,
+ const std::string& client_secret,
+ const std::string& refresh_token);
static bool ParseGetAccessTokenResponse(const content::URLFetcher* source,
std::string* access_token);
@@ -82,6 +88,8 @@ class OAuth2AccessTokenFetcher : public content::URLFetcherDelegate {
// While a fetch is in progress.
scoped_ptr<content::URLFetcher> fetcher_;
+ std::string client_id_;
+ std::string client_secret_;
std::string refresh_token_;
friend class OAuth2AccessTokenFetcherTest;
diff --git a/chrome/common/net/gaia/oauth2_access_token_fetcher_unittest.cc b/chrome/common/net/gaia/oauth2_access_token_fetcher_unittest.cc
index cbf3be5..e257cfb 100644
--- a/chrome/common/net/gaia/oauth2_access_token_fetcher_unittest.cc
+++ b/chrome/common/net/gaia/oauth2_access_token_fetcher_unittest.cc
@@ -114,14 +114,14 @@ class OAuth2AccessTokenFetcherTest : public testing::Test {
TEST_F(OAuth2AccessTokenFetcherTest, GetAccessTokenRequestFailure) {
TestURLFetcher* url_fetcher = SetupGetAccessToken(false, 0, "");
EXPECT_CALL(consumer_, OnGetTokenFailure(_)).Times(1);
- fetcher_.Start("refresh_token");
+ fetcher_.Start("client_id", "client_secret", "refresh_token");
fetcher_.OnURLFetchComplete(url_fetcher);
}
TEST_F(OAuth2AccessTokenFetcherTest, GetAccessTokenResponseCodeFailure) {
TestURLFetcher* url_fetcher = SetupGetAccessToken(true, RC_FORBIDDEN, "");
EXPECT_CALL(consumer_, OnGetTokenFailure(_)).Times(1);
- fetcher_.Start("refresh_token");
+ fetcher_.Start("client_id", "client_secret", "refresh_token");
fetcher_.OnURLFetchComplete(url_fetcher);
}
@@ -129,7 +129,7 @@ TEST_F(OAuth2AccessTokenFetcherTest, Success) {
TestURLFetcher* url_fetcher = SetupGetAccessToken(
true, RC_REQUEST_OK, kValidTokenResponse);
EXPECT_CALL(consumer_, OnGetTokenSuccess("at1")).Times(1);
- fetcher_.Start("refresh_token");
+ fetcher_.Start("client_id", "client_secret", "refresh_token");
fetcher_.OnURLFetchComplete(url_fetcher);
}