summaryrefslogtreecommitdiffstats
path: root/google_apis
diff options
context:
space:
mode:
authoratwilson@chromium.org <atwilson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-26 18:37:48 +0000
committeratwilson@chromium.org <atwilson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-26 18:37:48 +0000
commitf1fca5dc954093da2f80d355f9315a791e0cc7c9 (patch)
treed46a080fb55ee695f203487fe7aec15e8c34be29 /google_apis
parent38e4e0ad36b2c7a70ed8c6d653f1c7679ea8c558 (diff)
downloadchromium_src-f1fca5dc954093da2f80d355f9315a791e0cc7c9.zip
chromium_src-f1fca5dc954093da2f80d355f9315a791e0cc7c9.tar.gz
chromium_src-f1fca5dc954093da2f80d355f9315a791e0cc7c9.tar.bz2
Revert 267374 "Use new people.get api instead of oauth2/v1/useri..."
> Use new people.get api instead of oauth2/v1/userinfo. > Consolidate all uses into main helper class. > > Details about new api: https://developers.google.com/+/api/latest/people/get > > Format of returned response: https://developers.google.com/+/api/latest/people#resource > > BUG=320354,387707 > > Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=267068 > > Review URL: https://codereview.chromium.org/257773002 TBR=rogerta@chromium.org Review URL: https://codereview.chromium.org/354023006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@280060 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'google_apis')
-rw-r--r--google_apis/gaia/gaia_constants.cc5
-rw-r--r--google_apis/gaia/gaia_constants.h4
-rw-r--r--google_apis/gaia/gaia_oauth_client.cc60
-rw-r--r--google_apis/gaia/gaia_oauth_client.h18
-rw-r--r--google_apis/gaia/gaia_oauth_client_unittest.cc59
-rw-r--r--google_apis/gaia/gaia_urls.cc10
-rw-r--r--google_apis/gaia/gaia_urls.h4
7 files changed, 33 insertions, 127 deletions
diff --git a/google_apis/gaia/gaia_constants.cc b/google_apis/gaia/gaia_constants.cc
index 7dadc94..95a5945 100644
--- a/google_apis/gaia/gaia_constants.cc
+++ b/google_apis/gaia/gaia_constants.cc
@@ -45,11 +45,6 @@ const char kChromeSyncSupervisedOAuth2Scope[] =
const char kGoogleTalkOAuth2Scope[] =
"https://www.googleapis.com/auth/googletalk";
-const char kGoogleUserInfoEmail[] =
- "https://www.googleapis.com/auth/userinfo.email";
-const char kGoogleUserInfoProfile[] =
- "https://www.googleapis.com/auth/userinfo.profile";
-
// Used to mint uber auth tokens when needed.
const char kGaiaSid[] = "sid";
const char kGaiaLsid[] = "lsid";
diff --git a/google_apis/gaia/gaia_constants.h b/google_apis/gaia/gaia_constants.h
index 4786ac8..ea8cc0f 100644
--- a/google_apis/gaia/gaia_constants.h
+++ b/google_apis/gaia/gaia_constants.h
@@ -18,8 +18,6 @@ extern const char kGaiaService[]; // uber token
extern const char kPicasaService[];
extern const char kSyncService[];
extern const char kRemotingService[];
-
-// OAuth2 scopes.
extern const char kOAuth1LoginScope[];
extern const char kOAuthWrapBridgeUserInfoScope[];
extern const char kDeviceManagementServiceOAuth[];
@@ -27,8 +25,6 @@ extern const char kAnyApiOAuth2Scope[];
extern const char kChromeSyncOAuth2Scope[];
extern const char kChromeSyncSupervisedOAuth2Scope[];
extern const char kGoogleTalkOAuth2Scope[];
-extern const char kGoogleUserInfoEmail[];
-extern const char kGoogleUserInfoProfile[];
// Used with uber auth tokens when needed.
extern const char kGaiaSid[];
diff --git a/google_apis/gaia/gaia_oauth_client.cc b/google_apis/gaia/gaia_oauth_client.cc
index 1d5f9eb..1113ff6 100644
--- a/google_apis/gaia/gaia_oauth_client.cc
+++ b/google_apis/gaia/gaia_oauth_client.cc
@@ -56,9 +56,6 @@ class GaiaOAuthClient::Core
void GetUserId(const std::string& oauth_access_token,
int max_retries,
Delegate* delegate);
- void GetUserInfo(const std::string& oauth_access_token,
- int max_retries,
- Delegate* delegate);
void GetTokenInfo(const std::string& oauth_access_token,
int max_retries,
Delegate* delegate);
@@ -76,14 +73,13 @@ class GaiaOAuthClient::Core
TOKEN_INFO,
USER_EMAIL,
USER_ID,
- USER_INFO,
};
virtual ~Core() {}
- void PeopleGet(const std::string& oauth_access_token,
- int max_retries,
- Delegate* delegate);
+ void GetUserInfo(const std::string& oauth_access_token,
+ int max_retries,
+ Delegate* delegate);
void MakeGaiaRequest(const GURL& url,
const std::string& post_body,
int max_retries,
@@ -149,7 +145,7 @@ void GaiaOAuthClient::Core::GetUserEmail(const std::string& oauth_access_token,
DCHECK_EQ(request_type_, NO_PENDING_REQUEST);
DCHECK(!request_.get());
request_type_ = USER_EMAIL;
- PeopleGet(oauth_access_token, max_retries, delegate);
+ GetUserInfo(oauth_access_token, max_retries, delegate);
}
void GaiaOAuthClient::Core::GetUserId(const std::string& oauth_access_token,
@@ -158,25 +154,16 @@ void GaiaOAuthClient::Core::GetUserId(const std::string& oauth_access_token,
DCHECK_EQ(request_type_, NO_PENDING_REQUEST);
DCHECK(!request_.get());
request_type_ = USER_ID;
- PeopleGet(oauth_access_token, max_retries, delegate);
+ GetUserInfo(oauth_access_token, max_retries, delegate);
}
void GaiaOAuthClient::Core::GetUserInfo(const std::string& oauth_access_token,
int max_retries,
Delegate* delegate) {
- DCHECK_EQ(request_type_, NO_PENDING_REQUEST);
- DCHECK(!request_.get());
- request_type_ = USER_INFO;
- PeopleGet(oauth_access_token, max_retries, delegate);
-}
-
-void GaiaOAuthClient::Core::PeopleGet(const std::string& oauth_access_token,
- int max_retries,
- Delegate* delegate) {
delegate_ = delegate;
num_retries_ = 0;
request_.reset(net::URLFetcher::Create(
- kUrlFetcherId, GURL(GaiaUrls::GetInstance()->people_get_url()),
+ kUrlFetcherId, GURL(GaiaUrls::GetInstance()->oauth_user_info_url()),
net::URLFetcher::GET, this));
request_->SetRequestContext(request_context_getter_.get());
request_->AddExtraRequestHeader("Authorization: OAuth " + oauth_access_token);
@@ -295,27 +282,9 @@ void GaiaOAuthClient::Core::HandleResponse(
switch (type) {
case USER_EMAIL: {
- // Use first email of type "account" as the user's email.
- const base::ListValue* emails_list;
- bool email_found = false;
- if (response_dict->GetList("emails", &emails_list)) {
- for (size_t i = 0; i < emails_list->GetSize(); ++i) {
- const base::DictionaryValue* email_dict;
- if (emails_list->GetDictionary(i, &email_dict)) {
- std::string email;
- std::string type;
- if (email_dict->GetString("type", &type) &&
- type == "account" &&
- email_dict->GetString("value", &email)) {
- delegate_->OnGetUserEmailResponse(email);
- email_found = true;
- break;
- }
- }
- }
- }
- if (!email_found)
- delegate_->OnNetworkError(net::URLFetcher::RESPONSE_CODE_INVALID);
+ std::string email;
+ response_dict->GetString("email", &email);
+ delegate_->OnGetUserEmailResponse(email);
break;
}
@@ -326,11 +295,6 @@ void GaiaOAuthClient::Core::HandleResponse(
break;
}
- case USER_INFO: {
- delegate_->OnGetUserInfoResponse(response_dict.Pass());
- break;
- }
-
case TOKEN_INFO: {
delegate_->OnGetTokenInfoResponse(response_dict.Pass());
break;
@@ -408,12 +372,6 @@ void GaiaOAuthClient::GetUserId(const std::string& access_token,
return core_->GetUserId(access_token, max_retries, delegate);
}
-void GaiaOAuthClient::GetUserInfo(const std::string& access_token,
- int max_retries,
- Delegate* delegate) {
- return core_->GetUserInfo(access_token, max_retries, delegate);
-}
-
void GaiaOAuthClient::GetTokenInfo(const std::string& access_token,
int max_retries,
Delegate* delegate) {
diff --git a/google_apis/gaia/gaia_oauth_client.h b/google_apis/gaia/gaia_oauth_client.h
index fd13f46..8e01ef6 100644
--- a/google_apis/gaia/gaia_oauth_client.h
+++ b/google_apis/gaia/gaia_oauth_client.h
@@ -47,9 +47,6 @@ class GaiaOAuthClient {
virtual void OnGetUserEmailResponse(const std::string& user_email) {}
// Invoked on a successful response to the GetUserId request.
virtual void OnGetUserIdResponse(const std::string& user_id) {}
- // Invoked on a successful response to the GetUserInfo request.
- virtual void OnGetUserInfoResponse(
- scoped_ptr<base::DictionaryValue> user_info) {}
// Invoked on a successful response to the GetTokenInfo request.
virtual void OnGetTokenInfoResponse(
scoped_ptr<base::DictionaryValue> token_info) {}
@@ -91,7 +88,7 @@ class GaiaOAuthClient {
int max_retries,
Delegate* delegate);
- // Call the people.get API, returning the user email address associated
+ // Call the userinfo API, returning the user email address associated
// with the given access token. The provided access token must have
// https://www.googleapis.com/auth/userinfo.email as one of its scopes.
// See |max_retries| docs above.
@@ -99,23 +96,14 @@ class GaiaOAuthClient {
int max_retries,
Delegate* delegate);
- // Call the people.get API, returning the user gaia ID associated
+ // Call the userinfo API, returning the user gaia ID associated
// with the given access token. The provided access token must have
- // https://www.googleapis.com/auth/userinfo.profile as one of its scopes.
+ // https://www.googleapis.com/auth/userinfo as one of its scopes.
// See |max_retries| docs above.
void GetUserId(const std::string& oauth_access_token,
int max_retries,
Delegate* delegate);
- // Call the people.get API, returning the user info associated
- // with the given access token. The provided access token must have
- // https://www.googleapis.com/auth/userinfo.email and
- // https://www.googleapis.com/auth/userinfo.profile as its scopes.
- // See |max_retries| docs above.
- void GetUserInfo(const std::string& oauth_access_token,
- int max_retries,
- Delegate* delegate);
-
// Call the tokeninfo API, returning a dictionary of response values. The
// provided access token may have any scope, and basic results will be
// returned: issued_to, audience, scope, expires_in, access_type. In
diff --git a/google_apis/gaia/gaia_oauth_client_unittest.cc b/google_apis/gaia/gaia_oauth_client_unittest.cc
index 338578e..d4014f7 100644
--- a/google_apis/gaia/gaia_oauth_client_unittest.cc
+++ b/google_apis/gaia/gaia_oauth_client_unittest.cc
@@ -134,22 +134,25 @@ const std::string kTestUserId = "8675309";
const int kTestExpiresIn = 3920;
const std::string kDummyGetTokensResult =
- "{\"access_token\":\"" + kTestAccessToken + "\","
- "\"expires_in\":" + base::IntToString(kTestExpiresIn) + ","
- "\"refresh_token\":\"" + kTestRefreshToken + "\"}";
+ "{\"access_token\":\"" + kTestAccessToken + "\","
+ "\"expires_in\":" + base::IntToString(kTestExpiresIn) + ","
+ "\"refresh_token\":\"" + kTestRefreshToken + "\"}";
const std::string kDummyRefreshTokenResult =
- "{\"access_token\":\"" + kTestAccessToken + "\","
- "\"expires_in\":" + base::IntToString(kTestExpiresIn) + "}";
+ "{\"access_token\":\"" + kTestAccessToken + "\","
+ "\"expires_in\":" + base::IntToString(kTestExpiresIn) + "}";
+
+const std::string kDummyUserInfoResult =
+ "{\"email\":\"" + kTestUserEmail + "\"}";
const std::string kDummyUserIdResult =
- "{\"id\":\"" + kTestUserId + "\"}";
+ "{\"id\":\"" + kTestUserId + "\"}";
const std::string kDummyTokenInfoResult =
- "{\"issued_to\": \"1234567890.apps.googleusercontent.com\","
- "\"audience\": \"1234567890.apps.googleusercontent.com\","
- "\"scope\": \"https://googleapis.com/oauth2/v2/tokeninfo\","
- "\"expires_in\":" + base::IntToString(kTestExpiresIn) + "}";
+ "{\"issued_to\": \"1234567890.apps.googleusercontent.com\","
+ "\"audience\": \"1234567890.apps.googleusercontent.com\","
+ "\"scope\": \"https://googleapis.com/oauth2/v2/tokeninfo\","
+ "\"expires_in\":" + base::IntToString(kTestExpiresIn) + "}";
}
namespace gaia {
@@ -301,45 +304,11 @@ TEST_F(GaiaOAuthClientTest, RefreshTokenDownscopingSuccess) {
factory.get_url_fetcher()->Finish();
}
-TEST_F(GaiaOAuthClientTest, GetUserEmail) {
- MockGaiaOAuthClientDelegate delegate;
- EXPECT_CALL(delegate, OnGetUserEmailResponse(kTestUserEmail)).Times(1);
-
- const std::string kDummyUserInfoResult =
- "{\"emails\": [{\"value\":\"" + kTestUserEmail +
- "\", \"type\":\"account\"}]}";
-
- MockOAuthFetcherFactory factory;
- factory.set_results(kDummyUserInfoResult);
-
- GaiaOAuthClient auth(GetRequestContext());
- auth.GetUserEmail("access_token", 1, &delegate);
-}
-TEST_F(GaiaOAuthClientTest, GetUserEmailSecondItemValid) {
+TEST_F(GaiaOAuthClientTest, GetUserEmail) {
MockGaiaOAuthClientDelegate delegate;
EXPECT_CALL(delegate, OnGetUserEmailResponse(kTestUserEmail)).Times(1);
- const std::string kDummyUserInfoResult =
- "{\"emails\": [{\"value\":\"foo\"},"
- "{\"value\":\"" + kTestUserEmail +
- "\", \"type\":\"account\"}]}";
-
- MockOAuthFetcherFactory factory;
- factory.set_results(kDummyUserInfoResult);
-
- GaiaOAuthClient auth(GetRequestContext());
- auth.GetUserEmail("access_token", 1, &delegate);
-}
-
-TEST_F(GaiaOAuthClientTest, GetUserEmailNoValidItems) {
- MockGaiaOAuthClientDelegate delegate;
- EXPECT_CALL(delegate, OnNetworkError(_)).Times(1);
-
- const std::string kDummyUserInfoResult =
- "{\"emails\": [{\"value\":\"" + kTestUserEmail +
- "\", \"type\":\"foo\"}]}";
-
MockOAuthFetcherFactory factory;
factory.set_results(kDummyUserInfoResult);
diff --git a/google_apis/gaia/gaia_urls.cc b/google_apis/gaia/gaia_urls.cc
index 5abff9c..0b44a91 100644
--- a/google_apis/gaia/gaia_urls.cc
+++ b/google_apis/gaia/gaia_urls.cc
@@ -42,7 +42,7 @@ const char kOAuth2TokenUrlSuffix[] = "o/oauth2/token";
// API calls from www.googleapis.com
const char kOAuth2IssueTokenUrlSuffix[] = "oauth2/v2/IssueToken";
const char kOAuth2TokenInfoUrlSuffix[] = "oauth2/v2/tokeninfo";
-const char kPeopleGetUrlSuffix[] = "plus/v1/people/me";
+const char kOAuthUserInfoUrlSuffix[] = "oauth2/v1/userinfo";
void GetSwitchValueWithDefault(const char* switch_value,
const char* default_value,
@@ -118,8 +118,8 @@ GaiaUrls::GaiaUrls() {
google_apis_origin_url_.Resolve(kOAuth2IssueTokenUrlSuffix);
oauth2_token_info_url_ =
google_apis_origin_url_.Resolve(kOAuth2TokenInfoUrlSuffix);
- people_get_url_ =
- google_apis_origin_url_.Resolve(kPeopleGetUrlSuffix);
+ oauth_user_info_url_ =
+ google_apis_origin_url_.Resolve(kOAuthUserInfoUrlSuffix);
gaia_login_form_realm_ = gaia_url_;
}
@@ -179,8 +179,8 @@ const GURL& GaiaUrls::oauth_wrap_bridge_url() const {
return oauth_wrap_bridge_url_;
}
-const GURL& GaiaUrls::people_get_url() const {
- return people_get_url_;
+const GURL& GaiaUrls::oauth_user_info_url() const {
+ return oauth_user_info_url_;
}
const GURL& GaiaUrls::oauth_revoke_token_url() const {
diff --git a/google_apis/gaia/gaia_urls.h b/google_apis/gaia/gaia_urls.h
index 7a41ebf..f96e89c 100644
--- a/google_apis/gaia/gaia_urls.h
+++ b/google_apis/gaia/gaia_urls.h
@@ -24,12 +24,12 @@ class GaiaUrls {
const GURL& service_logout_url() const;
const GURL& issue_auth_token_url() const;
const GURL& get_user_info_url() const;
- const GURL& people_get_url() const;
const GURL& token_auth_url() const;
const GURL& merge_session_url() const;
const GURL& get_oauth_token_url() const;
const GURL& oauth_get_access_token_url() const;
const GURL& oauth_wrap_bridge_url() const;
+ const GURL& oauth_user_info_url() const;
const GURL& oauth_revoke_token_url() const;
const GURL& oauth1_login_url() const;
const GURL& list_accounts_url() const;
@@ -65,12 +65,12 @@ class GaiaUrls {
GURL service_logout_url_;
GURL issue_auth_token_url_;
GURL get_user_info_url_;
- GURL people_get_url_;
GURL token_auth_url_;
GURL merge_session_url_;
GURL get_oauth_token_url_;
GURL oauth_get_access_token_url_;
GURL oauth_wrap_bridge_url_;
+ GURL oauth_user_info_url_;
GURL oauth_revoke_token_url_;
GURL oauth1_login_url_;
GURL list_accounts_url_;