Last active
June 16, 2021 21:54
-
-
Save meenabassem/71fad2e24227f7cf94388511f51dd97b to your computer and use it in GitHub Desktop.
LoginManager.java - Facebook android SDK
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static final String PUBLISH_PERMISSION_PREFIX = "publish"; | |
private static final String MANAGE_PERMISSION_PREFIX = "manage"; | |
private static final String EXPRESS_LOGIN_ALLOWED = "express_login_allowed"; | |
private static final String PREFERENCE_LOGIN_MANAGER = "com.facebook.loginManager"; | |
private static final Set<String> OTHER_PUBLISH_PERMISSIONS = getOtherPublishPermissions(); | |
//source https://github.com/facebook/facebook-android-sdk/blob/1d9c7b1fe699389e25b44e3c52adac7e09df166d/facebook-common/src/main/java/com/facebook/login/LoginManager.java#L578-L588 | |
private static Set<String> getOtherPublishPermissions() { | |
HashSet<String> set = | |
new HashSet<String>() { | |
{ | |
add("ads_management"); | |
add("create_event"); | |
add("rsvp_event"); | |
} | |
}; | |
return Collections.unmodifiableSet(set); | |
} | |
//Source: https://github.com/facebook/facebook-android-sdk/blob/master/facebook-common/src/main/java/com/facebook/login/LoginManager.java#L413-L423 | |
/** | |
* Logs the user in with the requested read permissions. | |
* | |
* @param activity The activity which is starting the login process. | |
* @param permissions The requested permissions. | |
*/ | |
public void logInWithReadPermissions(Activity activity, Collection<String> permissions) { | |
validateReadPermissions(permissions); | |
logIn(activity, permissions); | |
} | |
//source https://github.com/facebook/facebook-android-sdk/blob/master/facebook-common/src/main/java/com/facebook/login/LoginManager.java#L542-L555 | |
private void validateReadPermissions(Collection<String> permissions) { | |
if (permissions == null) { | |
return; | |
} | |
for (String permission : permissions) { | |
if (isPublishPermission(permission)) { | |
throw new FacebookException( | |
String.format( | |
"Cannot pass a publish or manage permission (%s) to a request for read " | |
+ "authorization", | |
permission)); | |
} | |
} | |
} | |
//source https://github.com/facebook/facebook-android-sdk/blob/master/facebook-common/src/main/java/com/facebook/login/LoginManager.java#L571-L576 | |
static boolean isPublishPermission(String permission) { | |
return permission != null | |
&& (permission.startsWith(PUBLISH_PERMISSION_PREFIX) | |
|| permission.startsWith(MANAGE_PERMISSION_PREFIX) | |
|| OTHER_PUBLISH_PERMISSIONS.contains(permission)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment