use of com.facebook.AccessToken in project facebook-android-sdk by facebook.
the class LoginResultTest method testReAuth.
@Test
public void testReAuth() {
LoginClient.Request request = createRequest(EMAIL_SET, true);
AccessToken accessToken = createAccessToken(PROFILE_EMAIL_SET, new HashSet<String>());
LoginResult result = LoginManager.computeLoginResult(request, accessToken);
assertEquals(accessToken, result.getAccessToken());
assertEquals(EMAIL_SET, result.getRecentlyGrantedPermissions());
assertEquals(0, result.getRecentlyDeniedPermissions().size());
}
use of com.facebook.AccessToken in project facebook-android-sdk by facebook.
the class FacebookLiteLoginMethodHandlerTest method testFacebookLiteHandlesSuccess.
@Test
public void testFacebookLiteHandlesSuccess() {
Bundle bundle = new Bundle();
bundle.putLong("expires_in", EXPIRES_IN_DELTA);
bundle.putString("access_token", ACCESS_TOKEN);
bundle.putString("signed_request", SIGNED_REQUEST_STR);
Intent intent = new Intent();
intent.putExtras(bundle);
FacebookLiteLoginMethodHandler handler = new FacebookLiteLoginMethodHandler(mockLoginClient);
LoginClient.Request request = createRequest();
when(mockLoginClient.getPendingRequest()).thenReturn(request);
handler.tryAuthorize(request);
handler.onActivityResult(0, Activity.RESULT_OK, intent);
ArgumentCaptor<LoginClient.Result> resultArgumentCaptor = ArgumentCaptor.forClass(LoginClient.Result.class);
verify(mockLoginClient, times(1)).completeAndValidate(resultArgumentCaptor.capture());
LoginClient.Result result = resultArgumentCaptor.getValue();
assertNotNull(result);
assertEquals(LoginClient.Result.Code.SUCCESS, result.code);
AccessToken token = result.token;
assertNotNull(token);
assertEquals(ACCESS_TOKEN, token.getToken());
assertDateDiffersWithinDelta(new Date(), token.getExpires(), EXPIRES_IN_DELTA * 1000, 1000);
TestUtils.assertSamePermissions(PERMISSIONS, token.getPermissions());
}
use of com.facebook.AccessToken in project facebook-android-sdk by facebook.
the class GetTokenLoginMethodHandlerTest method testGetTokenHandlesSuccessWithAllPermissions.
@Test
public void testGetTokenHandlesSuccessWithAllPermissions() {
Bundle bundle = new Bundle();
bundle.putStringArrayList(NativeProtocol.EXTRA_PERMISSIONS, new ArrayList<String>(PERMISSIONS));
bundle.putLong(NativeProtocol.EXTRA_EXPIRES_SECONDS_SINCE_EPOCH, new Date().getTime() / 1000 + EXPIRES_IN_DELTA);
bundle.putString(NativeProtocol.EXTRA_ACCESS_TOKEN, ACCESS_TOKEN);
bundle.putString(NativeProtocol.EXTRA_USER_ID, USER_ID);
GetTokenLoginMethodHandler handler = new GetTokenLoginMethodHandler(mockLoginClient);
LoginClient.Request request = createRequest();
handler.getTokenCompleted(request, bundle);
ArgumentCaptor<LoginClient.Result> resultArgumentCaptor = ArgumentCaptor.forClass(LoginClient.Result.class);
verify(mockLoginClient, times(1)).completeAndValidate(resultArgumentCaptor.capture());
LoginClient.Result result = resultArgumentCaptor.getValue();
assertNotNull(result);
assertEquals(LoginClient.Result.Code.SUCCESS, result.code);
AccessToken token = result.token;
assertNotNull(token);
assertEquals(ACCESS_TOKEN, token.getToken());
assertDateDiffersWithinDelta(new Date(), token.getExpires(), EXPIRES_IN_DELTA * 1000, 1000);
TestUtils.assertSamePermissions(PERMISSIONS, token.getPermissions());
}
use of com.facebook.AccessToken in project facebook-android-sdk by facebook.
the class ShareApi method canShare.
/**
* Returns true if the content can be shared. Warns if the access token is missing the
* publish_actions permission. Doesn't fail when this permission is missing, because the app
* could have been granted that permission in another installation.
*
* @return true if the content can be shared.
*/
public boolean canShare() {
if (this.getShareContent() == null) {
return false;
}
final AccessToken accessToken = AccessToken.getCurrentAccessToken();
if (accessToken == null) {
return false;
}
final Set<String> permissions = accessToken.getPermissions();
if (permissions == null || !permissions.contains("publish_actions")) {
Log.w(TAG, "The publish_actions permissions are missing, the share will fail unless" + " this app was authorized to publish in another installation.");
}
return true;
}
use of com.facebook.AccessToken in project facebook-android-sdk by facebook.
the class NativeAppLoginMethodHandler method handleResultOk.
private LoginClient.Result handleResultOk(LoginClient.Request request, Intent data) {
Bundle extras = data.getExtras();
String error = getError(extras);
String errorCode = extras.getString("error_code");
String errorMessage = getErrorMessage(extras);
String e2e = extras.getString(NativeProtocol.FACEBOOK_PROXY_AUTH_E2E_KEY);
if (!Utility.isNullOrEmpty(e2e)) {
logWebLoginCompleted(e2e);
}
if (error == null && errorCode == null && errorMessage == null) {
try {
AccessToken token = createAccessTokenFromWebBundle(request.getPermissions(), extras, AccessTokenSource.FACEBOOK_APPLICATION_WEB, request.getApplicationId());
return LoginClient.Result.createTokenResult(request, token);
} catch (FacebookException ex) {
return LoginClient.Result.createErrorResult(request, null, ex.getMessage());
}
} else if (ServerProtocol.errorsProxyAuthDisabled.contains(error)) {
return null;
} else if (ServerProtocol.errorsUserCanceled.contains(error)) {
return LoginClient.Result.createCancelResult(request, null);
} else {
return LoginClient.Result.createErrorResult(request, error, errorMessage, errorCode);
}
}
Aggregations