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

Unified Diff: blimp/client/core/android/java/src/org/chromium/blimp/core/auth/Authenticator.java

Issue 2204223005: Blimp OAuth2 token retreival on application start up. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add deps file. Created 4 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: blimp/client/core/android/java/src/org/chromium/blimp/core/auth/Authenticator.java
diff --git a/blimp/client/core/android/java/src/org/chromium/blimp/core/auth/Authenticator.java b/blimp/client/core/android/java/src/org/chromium/blimp/core/auth/Authenticator.java
new file mode 100644
index 0000000000000000000000000000000000000000..1296685c7493c116b23fdbf9286a2c73a42d07fe
--- /dev/null
+++ b/blimp/client/core/android/java/src/org/chromium/blimp/core/auth/Authenticator.java
@@ -0,0 +1,53 @@
+// 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.
+
+package org.chromium.blimp.core.auth;
+
+import android.content.Context;
+
+import org.chromium.base.CommandLine;
+import org.chromium.base.ContextUtils;
+import org.chromium.blimp.core.BlimpClientSwitches;
+import org.chromium.blimp_public.BlimpClientContext;
+import org.chromium.components.sync.signin.AccountManagerHelper;
+import org.chromium.components.sync.signin.ChromeSigninController;
+
+/**
+ * Class to request OAuth2 token for Blimp.
+ */
+public class Authenticator {
+
+ private static final String SCOPE = "oauth2:https://www.googleapis.com/auth/userinfo.email";
+
+ private BlimpClientContext mBlimpClientContext;
+
+ public Authenticator(BlimpClientContext context) {
+ mBlimpClientContext = context;
+ }
+
+ /**
+ * Request OAuth2 token for Blimp if user signed in and we don't have command line argument
+ * {@link BlimpClientSwitches#ENGINE_IP}.
+ */
+ public void getAuthToken() {
+ final Context context = ContextUtils.getApplicationContext();
+ final AccountManagerHelper accountManagerHelper = AccountManagerHelper.get(context);
+ ChromeSigninController signin = ChromeSigninController.get(context);
+
+ if (signin.isSignedIn()
+ && !CommandLine.getInstance().hasSwitch(BlimpClientSwitches.ENGINE_IP)) {
+ accountManagerHelper.getAuthToken(signin.getSignedInUser(), SCOPE,
nyquist 2016/08/05 17:05:07 Since this does everything directly inside of blim
xingliu 2016/08/09 04:17:45 Done.
+ new AccountManagerHelper.GetAuthTokenCallback() {
+ @Override
+ public void tokenAvailable(String token) {
+ mBlimpClientContext.connect(token);
+ }
+
+ @Override
+ public void tokenUnavailable(boolean isTransientError) {
David Trainor- moved to gerrit 2016/08/05 15:49:09 Will this be handled in the future CL?
xingliu 2016/08/05 17:17:00 Should we show some error message and give user an
+ }
+ });
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698