summaryrefslogtreecommitdiffstats
path: root/google_apis/gaia/gaia_oauth_client.cc
diff options
context:
space:
mode:
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) {