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

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: Review comments 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
« no previous file with comments | « remoting/host/setup/host_starter.h ('k') | remoting/host/setup/service_client.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..3a0646bb8a37b18d00a39a11c433735d50267aef 100644
--- a/remoting/host/setup/host_starter.cc
+++ b/remoting/host/setup/host_starter.cc
@@ -95,30 +95,72 @@ void HostStarter::OnRefreshTokenResponse(
NOTREACHED();
}
+// This function is called twice: once with the host owner credentials, and once
+// with the service account credentials.
void HostStarter::OnGetUserEmailResponse(const std::string& user_email) {
if (!main_task_runner_->BelongsToCurrentThread()) {
main_task_runner_->PostTask(FROM_HERE, base::Bind(
&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_owner_.empty()) {
+ // This is the first callback, with the host owner credentials. Store the
+ // owner's email, and register the host.
+ host_owner_ = user_email;
+ 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 {
+ // This is the second callback, with the service account credentials.
+ // This email is the service account's email, used to login to XMPP.
+ 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 owner's credentials.
+ xmpp_login_ = host_owner_;
+ StartHostProcess();
return;
}
+
+ // 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_ != xmpp_login_) {
+ 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_);
« no previous file with comments | « remoting/host/setup/host_starter.h ('k') | remoting/host/setup/service_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698