summaryrefslogtreecommitdiffstats
path: root/google_apis/gaia/gaia_oauth_client.cc
diff options
context:
space:
mode:
authorrogerta@chromium.org <rogerta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-30 23:27:20 +0000
committerrogerta@chromium.org <rogerta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-30 23:27:20 +0000
commit431a075a671f8c7f1f31a90282f76af6e0cc94ff (patch)
tree0d0f540ddb318688b1613408c72030fc6700d094 /google_apis/gaia/gaia_oauth_client.cc
parentfca61dc53df4dbb46c2ee4bf075f662632418d61 (diff)
downloadchromium_src-431a075a671f8c7f1f31a90282f76af6e0cc94ff.zip
chromium_src-431a075a671f8c7f1f31a90282f76af6e0cc94ff.tar.gz
chromium_src-431a075a671f8c7f1f31a90282f76af6e0cc94ff.tar.bz2
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 Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=267068 Review URL: https://codereview.chromium.org/257773002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@267374 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'google_apis/gaia/gaia_oauth_client.cc')
-rw-r--r--google_apis/gaia/gaia_oauth_client.cc60
1 files changed, 51 insertions, 9 deletions
diff --git a/google_apis/gaia/gaia_oauth_client.cc b/google_apis/gaia/gaia_oauth_client.cc
index 1113ff6..1d5f9eb 100644
--- a/google_apis/gaia/gaia_oauth_client.cc
+++ b/google_apis/gaia/gaia_oauth_client.cc
@@ -56,6 +56,9 @@ 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);
@@ -73,13 +76,14 @@ class GaiaOAuthClient::Core
TOKEN_INFO,
USER_EMAIL,
USER_ID,
+ USER_INFO,
};
virtual ~Core() {}
- void GetUserInfo(const std::string& oauth_access_token,
- int max_retries,
- Delegate* delegate);
+ void PeopleGet(const std::string& oauth_access_token,
+ int max_retries,
+ Delegate* delegate);
void MakeGaiaRequest(const GURL& url,
const std::string& post_body,
int max_retries,
@@ -145,7 +149,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;
- GetUserInfo(oauth_access_token, max_retries, delegate);
+ PeopleGet(oauth_access_token, max_retries, delegate);
}
void GaiaOAuthClient::Core::GetUserId(const std::string& oauth_access_token,
@@ -154,16 +158,25 @@ void GaiaOAuthClient::Core::GetUserId(const std::string& oauth_access_token,
DCHECK_EQ(request_type_, NO_PENDING_REQUEST);
DCHECK(!request_.get());
request_type_ = USER_ID;
- GetUserInfo(oauth_access_token, max_retries, delegate);
+ PeopleGet(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()->oauth_user_info_url()),
+ kUrlFetcherId, GURL(GaiaUrls::GetInstance()->people_get_url()),
net::URLFetcher::GET, this));
request_->SetRequestContext(request_context_getter_.get());
request_->AddExtraRequestHeader("Authorization: OAuth " + oauth_access_token);
@@ -282,9 +295,27 @@ void GaiaOAuthClient::Core::HandleResponse(
switch (type) {
case USER_EMAIL: {
- std::string email;
- response_dict->GetString("email", &email);
- delegate_->OnGetUserEmailResponse(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);
break;
}
@@ -295,6 +326,11 @@ void GaiaOAuthClient::Core::HandleResponse(
break;
}
+ case USER_INFO: {
+ delegate_->OnGetUserInfoResponse(response_dict.Pass());
+ break;
+ }
+
case TOKEN_INFO: {
delegate_->OnGetTokenInfoResponse(response_dict.Pass());
break;
@@ -372,6 +408,12 @@ 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) {