OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/host/signaling_connector.h" | 5 #include "remoting/host/signaling_connector.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/strings/string_util.h" |
9 #include "google_apis/google_api_keys.h" | 10 #include "google_apis/google_api_keys.h" |
10 #include "net/url_request/url_fetcher.h" | 11 #include "net/url_request/url_fetcher.h" |
11 #include "net/url_request/url_request_context_getter.h" | 12 #include "net/url_request/url_request_context_getter.h" |
12 #include "remoting/host/dns_blackhole_checker.h" | 13 #include "remoting/host/dns_blackhole_checker.h" |
13 | 14 |
14 namespace remoting { | 15 namespace remoting { |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
18 // The delay between reconnect attempts will increase exponentially up | 19 // The delay between reconnect attempts will increase exponentially up |
19 // to the maximum specified here. | 20 // to the maximum specified here. |
20 const int kMaxReconnectDelaySeconds = 10 * 60; | 21 const int kMaxReconnectDelaySeconds = 10 * 60; |
21 | 22 |
22 // Time when we we try to update OAuth token before its expiration. | 23 // Time when we we try to update OAuth token before its expiration. |
23 const int kTokenUpdateTimeBeforeExpirySeconds = 60; | 24 const int kTokenUpdateTimeBeforeExpirySeconds = 60; |
24 | 25 |
25 } // namespace | 26 } // namespace |
26 | 27 |
27 SignalingConnector::OAuthCredentials::OAuthCredentials( | 28 SignalingConnector::OAuthCredentials::OAuthCredentials( |
28 const std::string& login_value, | 29 const std::string& login_value, |
29 const std::string& refresh_token_value) | 30 const std::string& refresh_token_value, |
| 31 bool is_service_account) |
30 : login(login_value), | 32 : login(login_value), |
31 refresh_token(refresh_token_value) { | 33 refresh_token(refresh_token_value), |
| 34 is_service_account(is_service_account) { |
32 } | 35 } |
33 | 36 |
34 SignalingConnector::SignalingConnector( | 37 SignalingConnector::SignalingConnector( |
35 XmppSignalStrategy* signal_strategy, | 38 XmppSignalStrategy* signal_strategy, |
36 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, | 39 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, |
37 scoped_ptr<DnsBlackholeChecker> dns_blackhole_checker, | 40 scoped_ptr<DnsBlackholeChecker> dns_blackhole_checker, |
38 const base::Closure& auth_failed_callback) | 41 const base::Closure& auth_failed_callback) |
39 : signal_strategy_(signal_strategy), | 42 : signal_strategy_(signal_strategy), |
40 url_request_context_getter_(url_request_context_getter), | 43 url_request_context_getter_(url_request_context_getter), |
41 auth_failed_callback_(auth_failed_callback), | 44 auth_failed_callback_(auth_failed_callback), |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 signal_strategy_->Connect(); | 224 signal_strategy_->Connect(); |
222 } | 225 } |
223 } | 226 } |
224 } | 227 } |
225 | 228 |
226 void SignalingConnector::RefreshOAuthToken() { | 229 void SignalingConnector::RefreshOAuthToken() { |
227 DCHECK(CalledOnValidThread()); | 230 DCHECK(CalledOnValidThread()); |
228 LOG(INFO) << "Refreshing OAuth token."; | 231 LOG(INFO) << "Refreshing OAuth token."; |
229 DCHECK(!refreshing_oauth_token_); | 232 DCHECK(!refreshing_oauth_token_); |
230 | 233 |
| 234 // Service accounts use different API keys, as they use the client app flow. |
| 235 google_apis::OAuth2Client oauth2_client; |
| 236 if (oauth_credentials_->is_service_account) { |
| 237 oauth2_client = google_apis::CLIENT_REMOTING_HOST; |
| 238 } else { |
| 239 oauth2_client = google_apis::CLIENT_REMOTING; |
| 240 } |
| 241 |
231 gaia::OAuthClientInfo client_info = { | 242 gaia::OAuthClientInfo client_info = { |
232 google_apis::GetOAuth2ClientID(google_apis::CLIENT_REMOTING), | 243 google_apis::GetOAuth2ClientID(oauth2_client), |
233 google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_REMOTING), | 244 google_apis::GetOAuth2ClientSecret(oauth2_client), |
234 // Redirect URL is only used when getting tokens from auth code. It | 245 // Redirect URL is only used when getting tokens from auth code. It |
235 // is not required when getting access tokens. | 246 // is not required when getting access tokens. |
236 "" | 247 "" |
237 }; | 248 }; |
238 | 249 |
239 refreshing_oauth_token_ = true; | 250 refreshing_oauth_token_ = true; |
240 std::vector<std::string> empty_scope_list; // (Use scope from refresh token.) | 251 std::vector<std::string> empty_scope_list; // (Use scope from refresh token.) |
241 gaia_oauth_client_->RefreshToken( | 252 gaia_oauth_client_->RefreshToken( |
242 client_info, oauth_credentials_->refresh_token, empty_scope_list, | 253 client_info, oauth_credentials_->refresh_token, empty_scope_list, |
243 1, this); | 254 1, this); |
244 } | 255 } |
245 | 256 |
246 } // namespace remoting | 257 } // namespace remoting |
OLD | NEW |