Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chromoting; | 5 package org.chromium.chromoting; |
| 6 | 6 |
| 7 import android.annotation.SuppressLint; | |
| 7 import android.app.Activity; | 8 import android.app.Activity; |
| 8 import android.content.ActivityNotFoundException; | 9 import android.content.ActivityNotFoundException; |
| 9 import android.content.ComponentName; | 10 import android.content.ComponentName; |
| 10 import android.content.Intent; | 11 import android.content.Intent; |
| 11 import android.content.pm.PackageManager; | 12 import android.content.pm.PackageManager; |
| 12 import android.net.Uri; | 13 import android.net.Uri; |
| 13 import android.text.TextUtils; | 14 import android.text.TextUtils; |
| 14 import android.util.Base64; | 15 import android.util.Base64; |
| 15 import android.util.Log; | 16 import android.util.Log; |
| 16 | 17 |
| 18 import java.io.IOException; | |
| 17 import java.security.SecureRandom; | 19 import java.security.SecureRandom; |
| 18 import java.util.ArrayList; | 20 import java.util.ArrayList; |
| 19 | 21 |
| 20 /** | 22 /** |
| 21 * This class is responsible for fetching a third party token from the user usin g the OAuth2 | 23 * This class is responsible for fetching a third party token from the user usin g the OAuth2 |
| 22 * implicit flow. It directs the user to a third party login page located at |t okenUrl|. It relies | 24 * implicit flow. It directs the user to a third party login page located at |t okenUrl|. It relies |
| 23 * on the |ThirdPartyTokenFetcher$OAuthRedirectActivity| to intercept the access token from the | 25 * on the |ThirdPartyTokenFetcher$OAuthRedirectActivity| to intercept the access token from the |
| 24 * redirect at intent://|REDIRECT_URI_PATH|#Intent;...end; upon successful login . | 26 * redirect at intent://|REDIRECT_URI_PATH|#Intent;...end; upon successful login . |
| 25 */ | 27 */ |
| 26 public class ThirdPartyTokenFetcher { | 28 public class ThirdPartyTokenFetcher { |
| 27 /** Callback for receiving the token. */ | 29 /** Callback for receiving the token. */ |
| 28 public interface Callback { | 30 public interface Callback { |
| 29 void onTokenFetched(String code, String accessToken); | 31 void onTokenFetched(String code, String accessToken); |
| 30 } | 32 } |
| 31 | 33 |
| 32 /** The path of the Redirect URI. */ | 34 /** The path of the Redirect URI. */ |
| 33 private static final String REDIRECT_URI_PATH = "/oauthredirect/"; | 35 private static final String REDIRECT_URI_PATH = "/oauthredirect/"; |
| 34 | 36 |
| 35 /** | 37 /** |
| 36 * Request both the authorization code and access token from the server. Se e | 38 * Request both the authorization code and access token from the server. Se e |
| 37 * http://tools.ietf.org/html/rfc6749#section-3.1.1. | 39 * http://tools.ietf.org/html/rfc6749#section-3.1.1. |
| 38 */ | 40 */ |
| 39 private static final String RESPONSE_TYPE = "code token"; | 41 private static final String RESPONSE_TYPE = "code token"; |
| 40 | 42 |
| 41 /** This is used to securely generate an opaque 128 bit for the |mState| var iable. */ | 43 /** This is used to securely generate an opaque 128 bit for the |mState| var iable. */ |
| 42 private static SecureRandom sSecureRandom = new SecureRandom(); | 44 @SuppressLint("TrulyRandom") |
| 45 private static SecureRandom sSecureRandom; | |
| 46 | |
| 47 // TODO(lambroslambrou): Refactor this class to only initialize a PRNG when ThirdPartyAuth is | |
| 48 // actually used. | |
| 49 static { | |
| 50 sSecureRandom = new SecureRandom(); | |
| 51 try { | |
| 52 SecureRandomInitializer.initialize(sSecureRandom); | |
|
palmer
2014/08/18 17:47:52
I almost wonder if the interface should instead be
Lambros
2014/08/18 20:31:31
I thought about that, but there are a lot of Secur
| |
| 53 } catch (IOException e) { | |
| 54 throw new RuntimeException("Failed to initialize PRNG: " + e); | |
| 55 } | |
| 56 } | |
| 43 | 57 |
| 44 /** This is used to launch the third party login page in the browser. */ | 58 /** This is used to launch the third party login page in the browser. */ |
| 45 private Activity mContext; | 59 private Activity mContext; |
| 46 | 60 |
| 47 /** | 61 /** |
| 48 * An opaque value used by the client to maintain state between the request and callback. The | 62 * An opaque value used by the client to maintain state between the request and callback. The |
| 49 * authorization server includes this value when redirecting the user-agent back to the client. | 63 * authorization server includes this value when redirecting the user-agent back to the client. |
| 50 * The parameter is used for preventing cross-site request forgery. See | 64 * The parameter is used for preventing cross-site request forgery. See |
| 51 * http://tools.ietf.org/html/rfc6749#section-10.12. | 65 * http://tools.ietf.org/html/rfc6749#section-10.12. |
| 52 */ | 66 */ |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 ComponentName component = new ComponentName( | 232 ComponentName component = new ComponentName( |
| 219 context.getApplicationContext(), | 233 context.getApplicationContext(), |
| 220 ThirdPartyTokenFetcher.OAuthRedirectActivity.class); | 234 ThirdPartyTokenFetcher.OAuthRedirectActivity.class); |
| 221 context.getPackageManager().setComponentEnabledSetting( | 235 context.getPackageManager().setComponentEnabledSetting( |
| 222 component, | 236 component, |
| 223 enabledState, | 237 enabledState, |
| 224 PackageManager.DONT_KILL_APP); | 238 PackageManager.DONT_KILL_APP); |
| 225 } | 239 } |
| 226 } | 240 } |
| 227 } | 241 } |
| OLD | NEW |