Skip to content

Commit fc4785c

Browse files
committed
Fixing Token refresh issue in SDK
Summary: The TokenRefresh intent is exposed as a service, but we were validating it as an activity. Fixign that and refactoring code. This code should have never worked. Note that without the FB app the refresh token feature will not work. If that is necessary, it's not part of this diff. Test Plan: Verify that hackbook can login & refresh token on the emulator. Reviewers: mmarucheck, yariv, ttung, raghuc1, trvish, pfung Reviewed By: mmarucheck CC: gregschechte, jacl, lshepard Differential Revision: https://phabricator.fb.com/D410960 Task ID: 926377
1 parent c58af0b commit fc4785c

File tree

1 file changed

+46
-11
lines changed

1 file changed

+46
-11
lines changed

facebook/src/com/facebook/android/Facebook.java

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ private boolean startSingleSignOn(Activity activity, String applicationId,
237237
// Verify that the application whose package name is
238238
// com.facebook.katana.ProxyAuth
239239
// has the expected FB app signature.
240-
if (!validateAppSignatureForIntent(activity, intent)) {
240+
if (!validateActivityIntent(activity, intent)) {
241241
return false;
242242
}
243243

@@ -254,24 +254,59 @@ private boolean startSingleSignOn(Activity activity, String applicationId,
254254
}
255255

256256
/**
257-
* Query the signature for the application that would be invoked by the
258-
* given intent and verify that it matches the FB application's signature.
257+
* Helper to validate an activity intent by resolving and checking the
258+
* provider's package signature.
259259
*
260260
* @param context
261261
* @param intent
262-
* @param validSignature
263-
* @return true if the app's signature matches the expected signature.
262+
* @return true if the service intent resolution happens successfully and the
263+
* signatures match.
264264
*/
265-
private boolean validateAppSignatureForIntent(Context context,
266-
Intent intent) {
265+
private boolean validateActivityIntent(Context context, Intent intent) {
266+
ResolveInfo resolveInfo =
267+
context.getPackageManager().resolveActivity(intent, 0);
268+
if (resolveInfo == null) {
269+
return false;
270+
}
267271

272+
return validateAppSignatureForPackage(
273+
context,
274+
resolveInfo.activityInfo.packageName);
275+
}
276+
277+
278+
/**
279+
* Helper to validate a service intent by resolving and checking the
280+
* provider's package signature.
281+
*
282+
* @param context
283+
* @param intent
284+
* @return true if the service intent resolution happens successfully and the
285+
* signatures match.
286+
*/
287+
private boolean validateServiceIntent(Context context, Intent intent) {
268288
ResolveInfo resolveInfo =
269-
context.getPackageManager().resolveActivity(intent, 0);
289+
context.getPackageManager().resolveService(intent, 0);
270290
if (resolveInfo == null) {
271291
return false;
272292
}
273293

274-
String packageName = resolveInfo.activityInfo.packageName;
294+
return validateAppSignatureForPackage(
295+
context,
296+
resolveInfo.serviceInfo.packageName);
297+
}
298+
299+
/**
300+
* Query the signature for the application that would be invoked by the
301+
* given intent and verify that it matches the FB application's signature.
302+
*
303+
* @param context
304+
* @param packageName
305+
* @return true if the app's signature matches the expected signature.
306+
*/
307+
private boolean validateAppSignatureForPackage(Context context,
308+
String packageName) {
309+
275310
PackageInfo packageInfo;
276311
try {
277312
packageInfo = context.getPackageManager().getPackageInfo(
@@ -382,7 +417,7 @@ public void authorizeCallback(int requestCode, int resultCode, Intent data) {
382417
if (description != null) {
383418
error = error + ":" + description;
384419
}
385-
Log.d("Facebook-authorize", "Login failed: " + error);
420+
Log.d("Facebook-authorize", "Login failed: " + error);
386421
mAuthDialogListener.onFacebookError(
387422
new FacebookError(error));
388423
}
@@ -453,7 +488,7 @@ public boolean extendAccessToken(Context context, ServiceListener serviceListene
453488
// Verify that the application whose package name is
454489
// com.facebook.katana
455490
// has the expected FB app signature.
456-
if (!validateAppSignatureForIntent(context, intent)) {
491+
if (!validateServiceIntent(context, intent)) {
457492
return false;
458493
}
459494

0 commit comments

Comments
 (0)