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.annotation.SuppressLint; |
8 import android.app.Activity; | 8 import android.app.Activity; |
9 import android.content.ActivityNotFoundException; | 9 import android.content.ActivityNotFoundException; |
10 import android.content.ComponentName; | 10 import android.content.ComponentName; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 this.mState = generateXsrfToken(); | 84 this.mState = generateXsrfToken(); |
85 this.mCallback = callback; | 85 this.mCallback = callback; |
86 this.mTokenUrlPatterns = tokenUrlPatterns; | 86 this.mTokenUrlPatterns = tokenUrlPatterns; |
87 | 87 |
88 this.mRedirectUriScheme = context.getApplicationContext().getPackageName
(); | 88 this.mRedirectUriScheme = context.getApplicationContext().getPackageName
(); |
89 | 89 |
90 // We don't follow the OAuth spec (http://tools.ietf.org/html/rfc6749#se
ction-3.1.2) of the | 90 // We don't follow the OAuth spec (http://tools.ietf.org/html/rfc6749#se
ction-3.1.2) of the |
91 // redirect URI as it is possible for the other applications to intercep
t the redirect URI. | 91 // redirect URI as it is possible for the other applications to intercep
t the redirect URI. |
92 // Instead, we use the intent scheme URI, which can restrict a specific
package to handle | 92 // Instead, we use the intent scheme URI, which can restrict a specific
package to handle |
93 // the intent. See https://developer.chrome.com/multidevice/android/int
ents. | 93 // the intent. See https://developer.chrome.com/multidevice/android/int
ents. |
94 this.mRedirectUri = "intent://" + REDIRECT_URI_PATH + "#Intent;" + | 94 this.mRedirectUri = "intent://" + REDIRECT_URI_PATH + "#Intent;" |
95 "package=" + mRedirectUriScheme + ";" + | 95 + "package=" + mRedirectUriScheme + ";" |
96 "scheme=" + mRedirectUriScheme + ";end;"; | 96 + "scheme=" + mRedirectUriScheme + ";end;"; |
97 } | 97 } |
98 | 98 |
99 /** | 99 /** |
100 * @param tokenUrl URL of the third party login page. | 100 * @param tokenUrl URL of the third party login page. |
101 * @param clientId The client identifier. See http://tools.ietf.org/html/rfc
6749#section-2.2. | 101 * @param clientId The client identifier. See http://tools.ietf.org/html/rfc
6749#section-2.2. |
102 * @param scope The scope of access request. See http://tools.ietf.org/html/
rfc6749#section-3.3. | 102 * @param scope The scope of access request. See http://tools.ietf.org/html/
rfc6749#section-3.3. |
103 */ | 103 */ |
104 public void fetchToken(String tokenUrl, String clientId, String scope) { | 104 public void fetchToken(String tokenUrl, String clientId, String scope) { |
105 if (!isValidTokenUrl(tokenUrl)) { | 105 if (!isValidTokenUrl(tokenUrl)) { |
106 failFetchToken( | 106 failFetchToken("Token URL does not match the domain\'s allowed URL p
atterns." |
107 "Token URL does not match the domain\'s allowed URL patterns
." + | 107 + " URL: " + tokenUrl |
108 " URL: " + tokenUrl + | 108 + ", patterns: " + TextUtils.join(",", this.mTokenUrlPattern
s)); |
109 ", patterns: " + TextUtils.join(",", this.mTokenUrlPatterns)
); | |
110 return; | 109 return; |
111 } | 110 } |
112 | 111 |
113 Uri uri = buildRequestUri(tokenUrl, clientId, scope); | 112 Uri uri = buildRequestUri(tokenUrl, clientId, scope); |
114 Intent intent = new Intent(Intent.ACTION_VIEW, uri); | 113 Intent intent = new Intent(Intent.ACTION_VIEW, uri); |
115 Log.i("ThirdPartyAuth", "fetchToken() url:" + uri); | 114 Log.i("ThirdPartyAuth", "fetchToken() url:" + uri); |
116 OAuthRedirectActivity.setEnabled(mContext, true); | 115 OAuthRedirectActivity.setEnabled(mContext, true); |
117 | 116 |
118 try { | 117 try { |
119 mContext.startActivity(intent); | 118 mContext.startActivity(intent); |
(...skipping 23 matching lines...) Expand all Loading... |
143 return false; | 142 return false; |
144 } | 143 } |
145 | 144 |
146 private boolean isValidIntent(Intent intent) { | 145 private boolean isValidIntent(Intent intent) { |
147 assert intent != null; | 146 assert intent != null; |
148 | 147 |
149 String action = intent.getAction(); | 148 String action = intent.getAction(); |
150 | 149 |
151 Uri data = intent.getData(); | 150 Uri data = intent.getData(); |
152 if (data != null) { | 151 if (data != null) { |
153 return Intent.ACTION_VIEW.equals(action) && | 152 return Intent.ACTION_VIEW.equals(action) |
154 this.mRedirectUriScheme.equals(data.getScheme()) && | 153 && this.mRedirectUriScheme.equals(data.getScheme()) |
155 REDIRECT_URI_PATH.equals(data.getPath()); | 154 && REDIRECT_URI_PATH.equals(data.getPath()); |
156 } | 155 } |
157 return false; | 156 return false; |
158 } | 157 } |
159 | 158 |
160 public boolean handleTokenFetched(Intent intent) { | 159 public boolean handleTokenFetched(Intent intent) { |
161 assert intent != null; | 160 assert intent != null; |
162 | 161 |
163 if (!isValidIntent(intent)) { | 162 if (!isValidIntent(intent)) { |
164 Log.w("ThirdPartyAuth", "Ignoring unmatched intent."); | 163 Log.w("ThirdPartyAuth", "Ignoring unmatched intent."); |
165 return false; | 164 return false; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 ComponentName component = new ComponentName( | 233 ComponentName component = new ComponentName( |
235 context.getApplicationContext(), | 234 context.getApplicationContext(), |
236 ThirdPartyTokenFetcher.OAuthRedirectActivity.class); | 235 ThirdPartyTokenFetcher.OAuthRedirectActivity.class); |
237 context.getPackageManager().setComponentEnabledSetting( | 236 context.getPackageManager().setComponentEnabledSetting( |
238 component, | 237 component, |
239 enabledState, | 238 enabledState, |
240 PackageManager.DONT_KILL_APP); | 239 PackageManager.DONT_KILL_APP); |
241 } | 240 } |
242 } | 241 } |
243 } | 242 } |
OLD | NEW |