Chromium Code Reviews| 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
|
| + } |
| + }); |
| + } |
| + } |
| +} |