| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "remoting/test/access_token_fetcher.h" | 5 #include "remoting/test/access_token_fetcher.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
| 14 #include "google_apis/gaia/gaia_constants.h" | 14 #include "google_apis/gaia/gaia_constants.h" |
| 15 #include "google_apis/google_api_keys.h" | 15 #include "google_apis/google_api_keys.h" |
| 16 #include "net/url_request/url_fetcher.h" | 16 #include "net/url_request/url_fetcher.h" |
| 17 #include "remoting/base/url_request_context_getter.h" | 17 #include "remoting/base/url_request_context_getter.h" |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 const int kMaxGetTokensRetries = 3; | 20 const int kMaxGetTokensRetries = 3; |
| 21 const char kOauthRedirectUrl[] = | 21 const char kOauthRedirectUrl[] = |
| 22 "https://chromoting-oauth.talkgadget." | 22 "https://chromoting-oauth.talkgadget." |
| 23 "google.com/talkgadget/oauth/chrome-remote-desktop/dev"; | 23 "google.com/talkgadget/oauth/chrome-remote-desktop/dev"; |
| 24 | |
| 25 // Factory function used to initialize our scope vector below, this is needed | |
| 26 // because initializer lists are only supported on C++11 compilers. | |
| 27 const std::vector<std::string> MakeAppRemotingScopeVector() { | |
| 28 std::vector<std::string> app_remoting_scopes; | |
| 29 | |
| 30 // Populate the vector with the required permissions for app remoting. | |
| 31 app_remoting_scopes.push_back( | |
| 32 "https://www.googleapis.com/auth/appremoting.runapplication"); | |
| 33 app_remoting_scopes.push_back("https://www.googleapis.com/auth/googletalk"); | |
| 34 app_remoting_scopes.push_back( | |
| 35 "https://www.googleapis.com/auth/userinfo.email"); | |
| 36 app_remoting_scopes.push_back("https://docs.google.com/feeds"); | |
| 37 app_remoting_scopes.push_back("https://www.googleapis.com/auth/drive"); | |
| 38 | |
| 39 return app_remoting_scopes; | |
| 40 } | |
| 41 | |
| 42 const std::vector<std::string> kAppRemotingScopeVector = | |
| 43 MakeAppRemotingScopeVector(); | |
| 44 } // namespace | 24 } // namespace |
| 45 | 25 |
| 46 namespace remoting { | 26 namespace remoting { |
| 47 namespace test { | 27 namespace test { |
| 48 | 28 |
| 49 AccessTokenFetcher::AccessTokenFetcher() { | 29 AccessTokenFetcher::AccessTokenFetcher() { |
| 50 oauth_client_info_ = { | 30 oauth_client_info_ = { |
| 51 google_apis::GetOAuth2ClientID(google_apis::CLIENT_REMOTING), | 31 google_apis::GetOAuth2ClientID(google_apis::CLIENT_REMOTING), |
| 52 google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_REMOTING), | 32 google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_REMOTING), |
| 53 kOauthRedirectUrl}; | 33 kOauthRedirectUrl}; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 | 66 |
| 87 access_token_.clear(); | 67 access_token_.clear(); |
| 88 refresh_token_ = refresh_token; | 68 refresh_token_ = refresh_token; |
| 89 access_token_callback_ = callback; | 69 access_token_callback_ = callback; |
| 90 | 70 |
| 91 // Create a new GaiaOAuthClient for each request to GAIA. | 71 // Create a new GaiaOAuthClient for each request to GAIA. |
| 92 CreateNewGaiaOAuthClientInstance(); | 72 CreateNewGaiaOAuthClientInstance(); |
| 93 auth_client_->RefreshToken( | 73 auth_client_->RefreshToken( |
| 94 oauth_client_info_, | 74 oauth_client_info_, |
| 95 refresh_token_, | 75 refresh_token_, |
| 96 kAppRemotingScopeVector, | 76 std::vector<std::string>(), // scopes |
| 97 kMaxGetTokensRetries, | 77 kMaxGetTokensRetries, |
| 98 this); // GaiaOAuthClient::Delegate* delegate | 78 this); // GaiaOAuthClient::Delegate* delegate |
| 99 } | 79 } |
| 100 | 80 |
| 101 void AccessTokenFetcher::CreateNewGaiaOAuthClientInstance() { | 81 void AccessTokenFetcher::CreateNewGaiaOAuthClientInstance() { |
| 102 scoped_refptr<remoting::URLRequestContextGetter> request_context_getter; | 82 scoped_refptr<remoting::URLRequestContextGetter> request_context_getter; |
| 103 request_context_getter = new remoting::URLRequestContextGetter( | 83 request_context_getter = new remoting::URLRequestContextGetter( |
| 104 base::ThreadTaskRunnerHandle::Get(), // network_runner | 84 base::ThreadTaskRunnerHandle::Get(), // network_runner |
| 105 base::ThreadTaskRunnerHandle::Get()); // file_runner | 85 base::ThreadTaskRunnerHandle::Get()); // file_runner |
| 106 | 86 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 std::string error_string; | 135 std::string error_string; |
| 156 std::string error_description; | 136 std::string error_description; |
| 157 | 137 |
| 158 // Check to see if the token_info we received had any errors, | 138 // Check to see if the token_info we received had any errors, |
| 159 // otherwise we will assume that it is valid for our purposes. | 139 // otherwise we will assume that it is valid for our purposes. |
| 160 if (token_info->HasKey("error")) { | 140 if (token_info->HasKey("error")) { |
| 161 token_info->GetString("error", &error_string); | 141 token_info->GetString("error", &error_string); |
| 162 token_info->GetString("error_description", &error_description); | 142 token_info->GetString("error_description", &error_description); |
| 163 | 143 |
| 164 LOG(ERROR) << "OnGetTokenInfoResponse returned an error. " | 144 LOG(ERROR) << "OnGetTokenInfoResponse returned an error. " |
| 165 << ", " | |
| 166 << "error: " << error_string << ", " | 145 << "error: " << error_string << ", " |
| 167 << "description: " << error_description; | 146 << "description: " << error_description; |
| 168 access_token_.clear(); | 147 access_token_.clear(); |
| 169 refresh_token_.clear(); | 148 refresh_token_.clear(); |
| 170 } else { | 149 } else { |
| 171 DVLOG(1) << "Access Token has been validated"; | 150 DVLOG(1) << "Access Token has been validated"; |
| 172 } | 151 } |
| 173 | 152 |
| 174 access_token_callback_.Run(access_token_, refresh_token_); | 153 access_token_callback_.Run(access_token_, refresh_token_); |
| 175 access_token_callback_.Reset(); | 154 access_token_callback_.Reset(); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 202 // Create a new GaiaOAuthClient for each request to GAIA. | 181 // Create a new GaiaOAuthClient for each request to GAIA. |
| 203 CreateNewGaiaOAuthClientInstance(); | 182 CreateNewGaiaOAuthClientInstance(); |
| 204 auth_client_->GetTokenInfo( | 183 auth_client_->GetTokenInfo( |
| 205 access_token_, | 184 access_token_, |
| 206 kMaxGetTokensRetries, | 185 kMaxGetTokensRetries, |
| 207 this); // GaiaOAuthClient::Delegate* delegate | 186 this); // GaiaOAuthClient::Delegate* delegate |
| 208 } | 187 } |
| 209 | 188 |
| 210 } // namespace test | 189 } // namespace test |
| 211 } // namespace remoting | 190 } // namespace remoting |
| OLD | NEW |