Search in sources :

Example 36 with AccessToken

use of com.facebook.AccessToken in project facebook-android-sdk by facebook.

the class LoginManagerTest method createSuccessResultIntent.

private Intent createSuccessResultIntent() {
    Intent intent = new Intent();
    Set<String> permissions = Sets.newSet("public_profile", "user_friends");
    LoginClient.Request request = new LoginClient.Request(null, permissions, null, null, null);
    AccessToken accessToken = createAccessToken();
    LoginClient.Result result = LoginClient.Result.createTokenResult(request, accessToken);
    intent.putExtra(LoginFragment.RESULT_KEY, result);
    return intent;
}
Also used : AccessToken(com.facebook.AccessToken) Intent(android.content.Intent)

Example 37 with AccessToken

use of com.facebook.AccessToken in project facebook-android-sdk by facebook.

the class LoginManagerTest method testLogInWithReadAndAccessTokenCreatesReauthRequest.

@Test
public void testLogInWithReadAndAccessTokenCreatesReauthRequest() {
    AccessToken accessToken = createAccessToken();
    stub(method(AccessToken.class, "getCurrentAccessToken")).toReturn(accessToken);
    LoginManager loginManager = new LoginManager();
    loginManager.logInWithReadPermissions(mockActivity, Arrays.asList("public_profile", "user_friends"));
    int loginRequestCode = CallbackManagerImpl.RequestCodeOffset.Login.toRequestCode();
    verify(mockActivity, times(1)).startActivityForResult(any(Intent.class), eq(loginRequestCode));
}
Also used : AccessToken(com.facebook.AccessToken) Intent(android.content.Intent) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 38 with AccessToken

use of com.facebook.AccessToken in project facebook-android-sdk by facebook.

the class LoginResultTest method testDeniedPermissions.

@Test
public void testDeniedPermissions() {
    LoginClient.Request request = createRequest(LIKES_EMAIL_SET, true);
    AccessToken accessToken = createAccessToken(EMAIL_SET, new HashSet<String>());
    LoginResult result = LoginManager.computeLoginResult(request, accessToken);
    assertEquals(accessToken, result.getAccessToken());
    assertEquals(EMAIL_SET, result.getRecentlyGrantedPermissions());
    assertEquals(new HashSet<String>() {

        {
            add("user_likes");
        }
    }, result.getRecentlyDeniedPermissions());
}
Also used : AccessToken(com.facebook.AccessToken) Test(org.junit.Test)

Example 39 with AccessToken

use of com.facebook.AccessToken in project facebook-android-sdk by facebook.

the class WebViewLoginMethodHandlerTest method testFromSSOWithExpiresString.

@Test
public void testFromSSOWithExpiresString() {
    List<String> permissions = Utility.arrayList("stream_publish", "go_outside_and_play");
    String token = "AnImaginaryTokenValue";
    Intent intent = new Intent();
    intent.putExtra("access_token", token);
    intent.putExtra("expires_in", "60");
    intent.putExtra("extra_extra", "Something unrelated");
    intent.putExtra("signed_request", SIGNED_REQUEST_STR);
    AccessToken accessToken = LoginMethodHandler.createAccessTokenFromWebBundle(permissions, intent.getExtras(), AccessTokenSource.FACEBOOK_APPLICATION_WEB, "1234");
    TestUtils.assertSamePermissions(permissions, accessToken);
    assertEquals(token, accessToken.getToken());
    assertEquals(AccessTokenSource.FACEBOOK_APPLICATION_WEB, accessToken.getSource());
    assertTrue(!accessToken.isExpired());
}
Also used : AccessToken(com.facebook.AccessToken) Intent(android.content.Intent) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 40 with AccessToken

use of com.facebook.AccessToken in project facebook-android-sdk by facebook.

the class CustomTabLoginMethodHandlerTest method testCustomTabHandlesSuccess.

@Test
public void testCustomTabHandlesSuccess() {
    final Bundle bundle = new Bundle();
    bundle.putString("access_token", ACCESS_TOKEN);
    bundle.putString("expires_in", String.format("%d", EXPIRES_IN_DELTA));
    bundle.putString("code", "Something else");
    bundle.putString("signed_request", SIGNED_REQUEST_STR);
    handler.onComplete(request, bundle, null);
    final ArgumentCaptor<LoginClient.Result> resultArgumentCaptor = ArgumentCaptor.forClass(LoginClient.Result.class);
    verify(mockLoginClient, times(1)).completeAndValidate(resultArgumentCaptor.capture());
    final LoginClient.Result result = resultArgumentCaptor.getValue();
    assertNotNull(result);
    assertEquals(LoginClient.Result.Code.SUCCESS, result.code);
    final 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) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

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