diff options
-rw-r--r-- | google_apis/gaia/gaia_oauth_client.cc | 18 | ||||
-rw-r--r-- | google_apis/gaia/gaia_oauth_client.h | 36 | ||||
-rw-r--r-- | google_apis/gaia/gaia_oauth_client_unittest.cc | 8 | ||||
-rw-r--r-- | remoting/host/setup/host_starter.cc | 6 | ||||
-rw-r--r-- | remoting/host/setup/host_starter.h | 2 | ||||
-rw-r--r-- | remoting/host/signaling_connector.cc | 4 | ||||
-rw-r--r-- | remoting/host/signaling_connector.h | 2 |
7 files changed, 50 insertions, 26 deletions
diff --git a/google_apis/gaia/gaia_oauth_client.cc b/google_apis/gaia/gaia_oauth_client.cc index d00b7d24e..a2b6dc5 100644 --- a/google_apis/gaia/gaia_oauth_client.cc +++ b/google_apis/gaia/gaia_oauth_client.cc @@ -49,9 +49,9 @@ class GaiaOAuthClient::Core 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 GetUserEmail(const std::string& oauth_access_token, + int max_retries, + Delegate* delegate); void GetTokenInfo(const std::string& oauth_access_token, int max_retries, Delegate* delegate); @@ -131,9 +131,9 @@ void GaiaOAuthClient::Core::RefreshToken( post_body, max_retries, delegate); } -void GaiaOAuthClient::Core::GetUserInfo(const std::string& oauth_access_token, - int max_retries, - Delegate* delegate) { +void GaiaOAuthClient::Core::GetUserEmail(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; @@ -253,7 +253,7 @@ void GaiaOAuthClient::Core::HandleResponse( case USER_INFO: { std::string email; response_dict->GetString("email", &email); - delegate_->OnGetUserInfoResponse(email); + delegate_->OnGetUserEmailResponse(email); break; } @@ -322,10 +322,10 @@ void GaiaOAuthClient::RefreshToken( delegate); } -void GaiaOAuthClient::GetUserInfo(const std::string& access_token, +void GaiaOAuthClient::GetUserEmail(const std::string& access_token, int max_retries, Delegate* delegate) { - return core_->GetUserInfo(access_token, max_retries, delegate); + return core_->GetUserEmail(access_token, max_retries, delegate); } void GaiaOAuthClient::GetTokenInfo(const std::string& access_token, diff --git a/google_apis/gaia/gaia_oauth_client.h b/google_apis/gaia/gaia_oauth_client.h index a8af658..94d3313 100644 --- a/google_apis/gaia/gaia_oauth_client.h +++ b/google_apis/gaia/gaia_oauth_client.h @@ -17,8 +17,9 @@ namespace net { class URLRequestContextGetter; } -// A helper class to get and refresh OAuth tokens given an authorization code. -// Also exposes utility methods for fetching user email and token owner. +// A helper class to get and refresh OAuth2 refresh and access tokens. +// Also exposes utility methods for fetching user email and token information. +// // Supports one request at a time; for parallel requests, create multiple // instances. namespace gaia { @@ -43,7 +44,7 @@ class GaiaOAuthClient { virtual void OnRefreshTokenResponse(const std::string& access_token, int expires_in_seconds) {} // Invoked on a successful response to the GetUserInfo request. - virtual void OnGetUserInfoResponse(const std::string& user_email) {} + virtual void OnGetUserEmailResponse(const std::string& user_email) {} // Invoked on a successful response to the GetTokenInfo request. virtual void OnGetTokenInfoResponse( scoped_ptr<DictionaryValue> token_info) {} @@ -65,18 +66,41 @@ class GaiaOAuthClient { // we should retry on a network error in invalid response. This does not // apply in the case of an OAuth error (i.e. there was something wrong with // the input arguments). Setting |max_retries| to -1 implies infinite retries. + + // Given an OAuth2 authorization code, fetch the long-lived refresh token + // and a valid access token. After the access token expires, RefreshToken() + // can be used to fetch a fresh access token. See |max_retries| docs above. void GetTokensFromAuthCode(const OAuthClientInfo& oauth_client_info, const std::string& auth_code, int max_retries, Delegate* delegate); + + // Given a valid refresh token (usually fetched via + // |GetTokensFromAuthCode()|), fetch a fresh access token that can be used + // to authenticate an API call. If |scopes| is non-empty, then fetch an + // access token for those specific scopes (assuming the refresh token has the + // appropriate permissions). See |max_retries| docs above. void RefreshToken(const OAuthClientInfo& oauth_client_info, const std::string& refresh_token, const std::vector<std::string>& scopes, int max_retries, Delegate* delegate); - void GetUserInfo(const std::string& oauth_access_token, - int max_retries, - Delegate* delegate); + + // 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. + void GetUserEmail(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 + // addition, if the https://www.googleapis.com/auth/userinfo.email scope is + // present, the email and verified_email fields will be returned. If the + // https://www.googleapis.com/auth/userinfo.profile scope is present, the + // user_id field will be returned. See |max_retries| docs above. void GetTokenInfo(const std::string& oauth_access_token, int max_retries, Delegate* delegate); diff --git a/google_apis/gaia/gaia_oauth_client_unittest.cc b/google_apis/gaia/gaia_oauth_client_unittest.cc index e91e4f6..acb366a 100644 --- a/google_apis/gaia/gaia_oauth_client_unittest.cc +++ b/google_apis/gaia/gaia_oauth_client_unittest.cc @@ -179,7 +179,7 @@ class MockGaiaOAuthClientDelegate : public gaia::GaiaOAuthClient::Delegate { int expires_in_seconds)); MOCK_METHOD2(OnRefreshTokenResponse, void(const std::string& access_token, int expires_in_seconds)); - MOCK_METHOD1(OnGetUserInfoResponse, void(const std::string& user_email)); + MOCK_METHOD1(OnGetUserEmailResponse, void(const std::string& user_email)); MOCK_METHOD0(OnOAuthError, void()); MOCK_METHOD1(OnNetworkError, void(int response_code)); @@ -294,15 +294,15 @@ TEST_F(GaiaOAuthClientTest, RefreshTokenDownscopingSuccess) { } -TEST_F(GaiaOAuthClientTest, GetUserInfo) { +TEST_F(GaiaOAuthClientTest, GetUserEmail) { MockGaiaOAuthClientDelegate delegate; - EXPECT_CALL(delegate, OnGetUserInfoResponse(kTestUserEmail)).Times(1); + EXPECT_CALL(delegate, OnGetUserEmailResponse(kTestUserEmail)).Times(1); MockOAuthFetcherFactory factory; factory.set_results(kDummyUserInfoResult); GaiaOAuthClient auth(profile_.GetRequestContext()); - auth.GetUserInfo("access_token", 1, &delegate); + auth.GetUserEmail("access_token", 1, &delegate); } TEST_F(GaiaOAuthClientTest, GetTokenInfo) { diff --git a/remoting/host/setup/host_starter.cc b/remoting/host/setup/host_starter.cc index 1d69ef0..d16137b 100644 --- a/remoting/host/setup/host_starter.cc +++ b/remoting/host/setup/host_starter.cc @@ -85,7 +85,7 @@ void HostStarter::OnGetTokensResponse( refresh_token_ = refresh_token; access_token_ = access_token; // Get the email corresponding to the access token. - oauth_client_->GetUserInfo(access_token_, 1, this); + oauth_client_->GetUserEmail(access_token_, 1, this); } void HostStarter::OnRefreshTokenResponse( @@ -95,10 +95,10 @@ void HostStarter::OnRefreshTokenResponse( NOTREACHED(); } -void HostStarter::OnGetUserInfoResponse(const std::string& user_email) { +void HostStarter::OnGetUserEmailResponse(const std::string& user_email) { if (!main_task_runner_->BelongsToCurrentThread()) { main_task_runner_->PostTask(FROM_HERE, base::Bind( - &HostStarter::OnGetUserInfoResponse, weak_ptr_, user_email)); + &HostStarter::OnGetUserEmailResponse, weak_ptr_, user_email)); return; } user_email_ = user_email; diff --git a/remoting/host/setup/host_starter.h b/remoting/host/setup/host_starter.h index a8b90f2..1d3b97f 100644 --- a/remoting/host/setup/host_starter.h +++ b/remoting/host/setup/host_starter.h @@ -52,7 +52,7 @@ class HostStarter : public gaia::GaiaOAuthClient::Delegate, int expires_in_seconds) OVERRIDE; virtual void OnRefreshTokenResponse(const std::string& access_token, int expires_in_seconds) OVERRIDE; - virtual void OnGetUserInfoResponse(const std::string& user_email) OVERRIDE; + virtual void OnGetUserEmailResponse(const std::string& user_email) OVERRIDE; // remoting::ServiceClient::Delegate virtual void OnHostRegistered() OVERRIDE; diff --git a/remoting/host/signaling_connector.cc b/remoting/host/signaling_connector.cc index 36af665..67c142f 100644 --- a/remoting/host/signaling_connector.cc +++ b/remoting/host/signaling_connector.cc @@ -125,10 +125,10 @@ void SignalingConnector::OnRefreshTokenResponse( base::TimeDelta::FromSeconds(expires_seconds) - base::TimeDelta::FromSeconds(kTokenUpdateTimeBeforeExpirySeconds); - gaia_oauth_client_->GetUserInfo(access_token, 1, this); + gaia_oauth_client_->GetUserEmail(access_token, 1, this); } -void SignalingConnector::OnGetUserInfoResponse(const std::string& user_email) { +void SignalingConnector::OnGetUserEmailResponse(const std::string& user_email) { DCHECK(CalledOnValidThread()); DCHECK(oauth_credentials_.get()); LOG(INFO) << "Received user info."; diff --git a/remoting/host/signaling_connector.h b/remoting/host/signaling_connector.h index ee175c6..c90823b 100644 --- a/remoting/host/signaling_connector.h +++ b/remoting/host/signaling_connector.h @@ -80,7 +80,7 @@ class SignalingConnector int expires_seconds) OVERRIDE; virtual void OnRefreshTokenResponse(const std::string& access_token, int expires_in_seconds) OVERRIDE; - virtual void OnGetUserInfoResponse(const std::string& user_email) OVERRIDE; + virtual void OnGetUserEmailResponse(const std::string& user_email) OVERRIDE; virtual void OnOAuthError() OVERRIDE; virtual void OnNetworkError(int response_code) OVERRIDE; |