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

Unified Diff: components/arc/auth/arc_auth_fetcher.cc

Issue 1618193003: arc: Pass auth token from Chrome to ARC instance. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update BUILD.gn Created 4 years, 11 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 | « components/arc/auth/arc_auth_fetcher.h ('k') | components/arc/test/fake_arc_bridge_service.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/arc/auth/arc_auth_fetcher.cc
diff --git a/components/arc/auth/arc_auth_fetcher.cc b/components/arc/auth/arc_auth_fetcher.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e67333fe430000af346a84b0ff91162bc82e24fb
--- /dev/null
+++ b/components/arc/auth/arc_auth_fetcher.cc
@@ -0,0 +1,59 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/arc/auth/arc_auth_fetcher.h"
+
+#include "base/strings/stringprintf.h"
+#include "google_apis/gaia/gaia_constants.h"
+#include "google_apis/gaia/gaia_urls.h"
+
+namespace arc {
+
+namespace {
+
+const char kGMSCoreClientId[] =
+ "1070009224336-sdh77n7uot3oc99ais00jmuft6sk2fg9.apps.googleusercontent.com";
+
+} // namespace
+
+ArcAuthFetcher::ArcAuthFetcher(net::URLRequestContextGetter* getter,
+ Delegate* delegate)
+ : delegate_(delegate), auth_fetcher_(this, std::string(), getter) {
+ FetchAuthCode();
+}
+
+// static
+GURL ArcAuthFetcher::CreateURL() {
+ std::string query_string =
+ base::StringPrintf("?scope=%s&client_id=%s",
+ GaiaConstants::kOAuth1LoginScope, kGMSCoreClientId);
+ return GaiaUrls::GetInstance()->client_login_to_oauth2_url().Resolve(
+ query_string);
+}
+
+void ArcAuthFetcher::FetchAuthCode() {
+ DCHECK(!auth_fetcher_.HasPendingFetch());
+ auth_fetcher_.StartCookieForOAuthLoginTokenExchange(
+ false, /* fetch_token_from_auth_code */
+ std::string(), /* session_index */
+ kGMSCoreClientId, std::string() /* device_id */);
+}
+
+void ArcAuthFetcher::OnClientOAuthCode(const std::string& auth_code) {
+ DCHECK(!auth_fetcher_.HasPendingFetch());
+ delegate_->OnAuthCodeFetched(auth_code);
+}
+
+void ArcAuthFetcher::OnClientOAuthFailure(const GoogleServiceAuthError& error) {
+ // UNEXPECTED_SERVICE_RESPONSE indicates no cookies in response, but request
+ // is completed successfully.
+ if (error.state() == GoogleServiceAuthError::UNEXPECTED_SERVICE_RESPONSE) {
+ delegate_->OnAuthCodeNeedUI();
+ } else {
+ VLOG(2) << "ARC Auth request failed: " << error.ToString() << ".";
+ delegate_->OnAuthCodeFailed();
+ }
+}
+
+} // namespace arc
« no previous file with comments | « components/arc/auth/arc_auth_fetcher.h ('k') | components/arc/test/fake_arc_bridge_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698