use of com.facebook.AccessToken in project facebook-android-sdk by facebook.
the class LoginClientTests method testReauthorizationWithDifferentFbidsFails.
@LargeTest
public void testReauthorizationWithDifferentFbidsFails() throws Exception {
TestBlocker blocker = getTestBlocker();
MockValidatingLoginClient client = new MockValidatingLoginClient(null, blocker);
client.addAccessTokenToFbidMapping(USER_1_ACCESS_TOKEN, USER_1_FBID);
client.addAccessTokenToFbidMapping(USER_2_ACCESS_TOKEN, USER_2_FBID);
client.setPermissionsToReport(PERMISSIONS);
LoginClient.Request request = createNewPermissionRequest();
client.setRequest(request);
AccessToken userOneToken = new AccessToken(USER_1_ACCESS_TOKEN, APP_ID, USER_1_FBID, PERMISSIONS, null, null, null, null);
AccessToken.setCurrentAccessToken(userOneToken);
AccessToken userTwoToken = new AccessToken(USER_2_ACCESS_TOKEN, APP_ID, USER_2_FBID, PERMISSIONS, null, null, null, null);
LoginClient.Result result = LoginClient.Result.createTokenResult(request, userTwoToken);
client.completeAndValidate(result);
blocker.waitForSignals(1);
assertNotNull(client.result);
assertEquals(LoginClient.Result.Code.ERROR, client.result.code);
assertNull(client.result.token);
assertNotNull(client.result.errorMessage);
}
use of com.facebook.AccessToken in project facebook-android-sdk by facebook.
the class DeviceAuthDialog method onSuccess.
private void onSuccess(final String accessToken) {
Bundle parameters = new Bundle();
parameters.putString("fields", "id,permissions,name");
AccessToken temporaryToken = new AccessToken(accessToken, FacebookSdk.getApplicationId(), "0", null, null, null, null, null);
GraphRequest request = new GraphRequest(temporaryToken, "me", parameters, HttpMethod.GET, new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse response) {
if (completed.get()) {
return;
}
if (response.getError() != null) {
onError(response.getError().getException());
return;
}
String userId;
Utility.PermissionsPair permissions;
String name;
try {
JSONObject jsonObject = response.getJSONObject();
userId = jsonObject.getString("id");
permissions = Utility.handlePermissionResponse(jsonObject);
name = jsonObject.getString("name");
} catch (JSONException ex) {
onError(new FacebookException(ex));
return;
}
DeviceRequestsHelper.cleanUpAdvertisementService(currentRequestState.getUserCode());
boolean requireConfirm = FetchedAppSettingsManager.getAppSettingsWithoutQuery(FacebookSdk.getApplicationId()).getSmartLoginOptions().contains(SmartLoginOption.RequireConfirm);
if (requireConfirm && !isRetry) {
isRetry = true;
presentConfirmation(userId, permissions, accessToken, name);
return;
}
completeLogin(userId, permissions, accessToken);
}
});
request.executeAsync();
}
use of com.facebook.AccessToken in project facebook-android-sdk by facebook.
the class LoginClient method validateSameFbidAndFinish.
void validateSameFbidAndFinish(Result pendingResult) {
if (pendingResult.token == null) {
throw new FacebookException("Can't validate without a token");
}
AccessToken previousToken = AccessToken.getCurrentAccessToken();
AccessToken newToken = pendingResult.token;
try {
Result result;
if (previousToken != null && newToken != null && previousToken.getUserId().equals(newToken.getUserId())) {
result = Result.createTokenResult(pendingRequest, pendingResult.token);
} else {
result = Result.createErrorResult(pendingRequest, "User logged in as different Facebook user.", null);
}
complete(result);
} catch (Exception ex) {
complete(Result.createErrorResult(pendingRequest, "Caught exception", ex.getMessage()));
}
}
use of com.facebook.AccessToken in project facebook-android-sdk by facebook.
the class LoginButton method configureButton.
@Override
protected void configureButton(final Context context, final AttributeSet attrs, final int defStyleAttr, final int defStyleRes) {
super.configureButton(context, attrs, defStyleAttr, defStyleRes);
setInternalOnClickListener(getNewLoginClickListener());
parseLoginButtonAttributes(context, attrs, defStyleAttr, defStyleRes);
if (isInEditMode()) {
// cannot use a drawable in edit mode, so setting the background color instead
// of a background resource.
setBackgroundColor(getResources().getColor(R.color.com_facebook_blue));
// hardcoding in edit mode as getResources().getString() doesn't seem to work in
// IntelliJ
loginText = "Continue with Facebook";
} else {
accessTokenTracker = new AccessTokenTracker() {
@Override
protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken currentAccessToken) {
setButtonText();
}
};
}
setButtonText();
// set vector drawables on the button
setCompoundDrawablesWithIntrinsicBounds(AppCompatResources.getDrawable(getContext(), R.drawable.com_facebook_button_login_logo), null, null, null);
}
use of com.facebook.AccessToken in project facebook-android-sdk by facebook.
the class LoginMethodHandler method createAccessTokenFromWebBundle.
public static AccessToken createAccessTokenFromWebBundle(Collection<String> requestedPermissions, Bundle bundle, AccessTokenSource source, String applicationId) throws FacebookException {
Date expires = Utility.getBundleLongAsDate(bundle, AccessToken.EXPIRES_IN_KEY, new Date());
String token = bundle.getString(AccessToken.ACCESS_TOKEN_KEY);
// With Login v4, we now get back the actual permissions granted, so update the permissions
// to be the real thing
String grantedPermissions = bundle.getString("granted_scopes");
if (!Utility.isNullOrEmpty(grantedPermissions)) {
requestedPermissions = new ArrayList<String>(Arrays.asList(grantedPermissions.split(",")));
}
String deniedPermissions = bundle.getString("denied_scopes");
List<String> declinedPermissions = null;
if (!Utility.isNullOrEmpty(deniedPermissions)) {
declinedPermissions = new ArrayList<String>(Arrays.asList(deniedPermissions.split(",")));
}
if (Utility.isNullOrEmpty(token)) {
return null;
}
String signed_request = bundle.getString("signed_request");
String userId = getUserIDFromSignedRequest(signed_request);
return new AccessToken(token, applicationId, userId, requestedPermissions, declinedPermissions, source, expires, new Date());
}
Aggregations