Search in sources :

Example 21 with AccessToken

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());
}
Also used : AccessToken(com.facebook.AccessToken) Test(org.junit.Test)

Example 22 with AccessToken

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());
}
Also used : Bundle(android.os.Bundle) AccessToken(com.facebook.AccessToken) Intent(android.content.Intent) Date(java.util.Date) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 23 with AccessToken

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());
}
Also used : Bundle(android.os.Bundle) AccessToken(com.facebook.AccessToken) Date(java.util.Date) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 24 with AccessToken

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;
}
Also used : AccessToken(com.facebook.AccessToken)

Example 25 with AccessToken

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);
    }
}
Also used : Bundle(android.os.Bundle) AccessToken(com.facebook.AccessToken) FacebookException(com.facebook.FacebookException)

Aggregations

AccessToken (com.facebook.AccessToken)49 Test (org.junit.Test)16 Bundle (android.os.Bundle)14 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)13 Date (java.util.Date)9 Intent (android.content.Intent)8 AccessTokenTracker (com.facebook.AccessTokenTracker)7 FacebookException (com.facebook.FacebookException)7 GraphRequest (com.facebook.GraphRequest)5 GraphResponse (com.facebook.GraphResponse)4 JSONObject (org.json.JSONObject)4 JSONException (org.json.JSONException)3 IntentFilter (android.content.IntentFilter)2 LocalBroadcastManager (android.support.v4.content.LocalBroadcastManager)2 LargeTest (android.test.suitebuilder.annotation.LargeTest)2 Profile (com.facebook.Profile)2 ProfileTracker (com.facebook.ProfileTracker)2 TestBlocker (com.facebook.TestBlocker)2 WaitForBroadcastReceiver (com.facebook.WaitForBroadcastReceiver)2 AppEventsLogger (com.facebook.appevents.AppEventsLogger)2