Chromium Code Reviews| Index: google_apis/gaia/gaia_oauth_client.cc |
| diff --git a/google_apis/gaia/gaia_oauth_client.cc b/google_apis/gaia/gaia_oauth_client.cc |
| index 7b543db881e19979e6a74758c545ab7e3e33addd..cc4b6838b3dd058ff60d5c319f8f15b97e542410 100644 |
| --- a/google_apis/gaia/gaia_oauth_client.cc |
| +++ b/google_apis/gaia/gaia_oauth_client.cc |
| @@ -7,6 +7,7 @@ |
| #include "base/json/json_reader.h" |
| #include "base/logging.h" |
| #include "base/memory/scoped_ptr.h" |
| +#include "base/string_util.cc" |
| #include "base/values.h" |
| #include "google_apis/gaia/gaia_urls.h" |
| #include "googleurl/src/gurl.h" |
| @@ -43,9 +44,13 @@ class GaiaOAuthClient::Core |
| GaiaOAuthClient::Delegate* delegate); |
| void RefreshToken(const OAuthClientInfo& oauth_client_info, |
| const std::string& refresh_token, |
| + const std::vector<std::string>& scopes, |
| int max_retries, |
| GaiaOAuthClient::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); |
| @@ -59,12 +64,14 @@ class GaiaOAuthClient::Core |
| NO_PENDING_REQUEST, |
| TOKENS_FROM_AUTH_CODE, |
| REFRESH_TOKEN, |
| + TOKEN_INFO, |
| USER_INFO, |
| }; |
| virtual ~Core() {} |
| - void MakeGaiaRequest(const std::string& post_body, |
| + void MakeGaiaRequest(const GURL& url, |
| + const std::string& post_body, |
| int max_retries, |
| GaiaOAuthClient::Delegate* delegate); |
| void HandleResponse(const net::URLFetcher* source, |
| @@ -94,12 +101,13 @@ void GaiaOAuthClient::Core::GetTokensFromAuthCode( |
| "&redirect_uri=" + |
| net::EscapeUrlEncodedData(oauth_client_info.redirect_uri, true) + |
| "&grant_type=authorization_code"; |
| - MakeGaiaRequest(post_body, max_retries, delegate); |
| + MakeGaiaRequest(gaia_url_, post_body, max_retries, delegate); |
| } |
| void GaiaOAuthClient::Core::RefreshToken( |
| const OAuthClientInfo& oauth_client_info, |
| const std::string& refresh_token, |
| + const std::vector<std::string>& scopes, |
| int max_retries, |
| GaiaOAuthClient::Delegate* delegate) { |
| DCHECK_EQ(request_type_, NO_PENDING_REQUEST); |
| @@ -111,7 +119,27 @@ void GaiaOAuthClient::Core::RefreshToken( |
| "&client_secret=" + |
| net::EscapeUrlEncodedData(oauth_client_info.client_secret, true) + |
| "&grant_type=refresh_token"; |
| - MakeGaiaRequest(post_body, max_retries, delegate); |
| + |
| + if (!scopes.empty()) { |
| + std::string scopes_string = JoinString(scopes, ' '); |
| + post_body += "&scope=" + net::EscapeUrlEncodedData(scopes_string, true); |
| + } |
| + |
| + MakeGaiaRequest(gaia_url_, post_body, max_retries, delegate); |
| +} |
| + |
| +void GaiaOAuthClient::Core::GetTokenInfo(const std::string& oauth_access_token, |
|
Mattias Nissler (ping if slow)
2013/06/17 05:34:17
Hm, shouldn't this logically be closer to GetUserI
David Roche
2013/06/18 04:12:08
I'm not sure I follow. Are you saying to keep the
|
| + 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); |
| + MakeGaiaRequest(GURL(GaiaUrls::GetInstance()->oauth2_token_info_url()), |
| + post_body, |
| + max_retries, |
| + delegate); |
| } |
| void GaiaOAuthClient::Core::GetUserInfo(const std::string& oauth_access_token, |
| @@ -137,6 +165,7 @@ void GaiaOAuthClient::Core::GetUserInfo(const std::string& oauth_access_token, |
| } |
| void GaiaOAuthClient::Core::MakeGaiaRequest( |
| + const GURL& url, |
| const std::string& post_body, |
| int max_retries, |
| GaiaOAuthClient::Delegate* delegate) { |
| @@ -144,7 +173,7 @@ void GaiaOAuthClient::Core::MakeGaiaRequest( |
| delegate_ = delegate; |
| num_retries_ = 0; |
| request_.reset(net::URLFetcher::Create( |
| - 0, gaia_url_, net::URLFetcher::POST, this)); |
| + 0, url, net::URLFetcher::POST, this)); |
| request_->SetRequestContext(request_context_getter_.get()); |
| request_->SetUploadData("application/x-www-form-urlencoded", post_body); |
| request_->SetMaxRetriesOn5xx(max_retries); |
| @@ -223,6 +252,11 @@ void GaiaOAuthClient::Core::HandleResponse( |
| break; |
| } |
| + case TOKEN_INFO: { |
| + delegate_->OnGetTokenInfoResponse(response_dict.Pass()); |
| + break; |
| + } |
| + |
| case TOKENS_FROM_AUTH_CODE: |
| case REFRESH_TOKEN: { |
| std::string access_token; |
| @@ -252,6 +286,7 @@ void GaiaOAuthClient::Core::HandleResponse( |
| } |
| } |
| +// TODO: remove passed-in gaia_url? |
|
Mattias Nissler (ping if slow)
2013/06/17 05:34:17
TODOs without owners/bugs are not worth much...
David Roche
2013/06/18 04:12:08
Oops, left that as a note to be cleaned up before
|
| GaiaOAuthClient::GaiaOAuthClient(const std::string& gaia_url, |
| net::URLRequestContextGetter* context_getter) { |
| core_ = new Core(gaia_url, context_getter); |
| @@ -271,12 +306,15 @@ void GaiaOAuthClient::GetTokensFromAuthCode( |
| delegate); |
| } |
| -void GaiaOAuthClient::RefreshToken(const OAuthClientInfo& oauth_client_info, |
| - const std::string& refresh_token, |
| - int max_retries, |
| - Delegate* delegate) { |
| +void GaiaOAuthClient::RefreshToken( |
| + const OAuthClientInfo& oauth_client_info, |
| + const std::string& refresh_token, |
| + const std::vector<std::string>& scopes, |
| + int max_retries, |
| + Delegate* delegate) { |
| return core_->RefreshToken(oauth_client_info, |
| refresh_token, |
| + scopes, |
| max_retries, |
| delegate); |
| } |
| @@ -287,4 +325,10 @@ void GaiaOAuthClient::GetUserInfo(const std::string& access_token, |
| return core_->GetUserInfo(access_token, max_retries, delegate); |
| } |
| +void GaiaOAuthClient::GetTokenInfo(const std::string& access_token, |
| + int max_retries, |
| + Delegate* delegate) { |
| + return core_->GetTokenInfo(access_token, max_retries, delegate); |
| +} |
| + |
| } // namespace gaia |