Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Unified Diff: remoting/host/setup/host_starter.cc

Issue 22992002: Service account setup for headless Linux hosts (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: remoting/host/setup/host_starter.cc
diff --git a/remoting/host/setup/host_starter.cc b/remoting/host/setup/host_starter.cc
index d16137bed6ceeaf77075a50395776fa150fed080..159cad18c3ee4aab767cf19ba706d05ff94e2135 100644
--- a/remoting/host/setup/host_starter.cc
+++ b/remoting/host/setup/host_starter.cc
@@ -101,24 +101,62 @@ void HostStarter::OnGetUserEmailResponse(const std::string& user_email) {
&HostStarter::OnGetUserEmailResponse, weak_ptr_, user_email));
return;
}
- user_email_ = user_email;
- // Register the host.
- host_id_ = base::GenerateGUID();
- key_pair_ = RsaKeyPair::Generate();
- service_client_->RegisterHost(
- host_id_, host_name_, key_pair_->GetPublicKey(), access_token_, this);
+
+ if (host_id_.empty()) {
Sergey Ulanov 2013/08/13 23:33:38 Add a comment that this function is used for both
rmsousa 2013/08/14 02:13:12 Done.
+ // Register the host.
+ xmpp_login_ = user_email;
Sergey Ulanov 2013/08/13 23:33:38 I think it's better to set host_owner_ here and co
rmsousa 2013/08/14 02:13:12 Done.
+ host_id_ = base::GenerateGUID();
+ key_pair_ = RsaKeyPair::Generate();
+
+ std::string host_client_id;
+ host_client_id = google_apis::GetOAuth2ClientID(
+ google_apis::CLIENT_REMOTING_HOST);
+
+ service_client_->RegisterHost(
+ host_id_, host_name_, key_pair_->GetPublicKey(), host_client_id,
+ access_token_, this);
+ } else {
+ // Host is already registered, this response is for the service account.
+ // The previous value of xmpp_login is the host owner's email.
+ host_owner_ = xmpp_login_;
+ xmpp_login_ = user_email;
+ StartHostProcess();
+ }
}
-void HostStarter::OnHostRegistered() {
+void HostStarter::OnHostRegistered(const std::string& authorization_code) {
if (!main_task_runner_->BelongsToCurrentThread()) {
main_task_runner_->PostTask(FROM_HERE, base::Bind(
- &HostStarter::OnHostRegistered, weak_ptr_));
+ &HostStarter::OnHostRegistered, weak_ptr_, authorization_code));
return;
}
+
+ if (authorization_code.empty()) {
+ // No service account code, start the host with the user's credentials.
+ StartHostProcess();
+ } else {
Sergey Ulanov 2013/08/13 23:33:38 add return in the case above and remove else. The
rmsousa 2013/08/14 02:13:12 Done.
+ // Received a service account authorization code, update oauth_client_info_
+ // to use the service account client keys, and get service account tokens.
+ oauth_client_info_.client_id =
+ google_apis::GetOAuth2ClientID(
+ google_apis::CLIENT_REMOTING_HOST);
+ oauth_client_info_.client_secret =
+ google_apis::GetOAuth2ClientSecret(
+ google_apis::CLIENT_REMOTING_HOST);
+ oauth_client_info_.redirect_uri = "oob";
+ oauth_client_->GetTokensFromAuthCode(
+ oauth_client_info_, authorization_code, kMaxGetTokensRetries, this);
+ }
+}
+
+void HostStarter::StartHostProcess() {
// Start the host.
std::string host_secret_hash = remoting::MakeHostPinHash(host_id_, host_pin_);
scoped_ptr<base::DictionaryValue> config(new base::DictionaryValue());
- config->SetString("xmpp_login", user_email_);
+ if (!host_owner_.empty()) {
Sergey Ulanov 2013/08/13 23:33:38 Can we always set host_owner, even when using user
rmsousa 2013/08/14 02:13:12 https://codereview.chromium.org/19796006/ uses the
+ config->SetString("host_owner", host_owner_);
+ }
+ config->SetString("xmpp_login", xmpp_login_);
config->SetString("oauth_refresh_token", refresh_token_);
config->SetString("host_id", host_id_);
config->SetString("host_name", host_name_);

Powered by Google App Engine
This is Rietveld 408576698