use of com.facebook.AccessToken in project facebook-android-sdk by facebook.
the class WebViewLoginMethodHandlerTest method testFromDialog.
@Test
public void testFromDialog() {
List<String> permissions = Utility.arrayList("stream_publish", "go_outside_and_play");
String token = "AnImaginaryTokenValue";
String userId = "1000";
Bundle bundle = new Bundle();
bundle.putString("access_token", token);
bundle.putString("expires_in", "60");
bundle.putString("signed_request", SIGNED_REQUEST_STR);
AccessToken accessToken = LoginMethodHandler.createAccessTokenFromWebBundle(permissions, bundle, AccessTokenSource.WEB_VIEW, "1234");
TestUtils.assertSamePermissions(permissions, accessToken);
assertEquals(token, accessToken.getToken());
assertEquals(AccessTokenSource.WEB_VIEW, accessToken.getSource());
assertTrue(!accessToken.isExpired());
}
use of com.facebook.AccessToken in project facebook-android-sdk by facebook.
the class WebViewLoginMethodHandlerTest method testWebViewHandlesSuccess.
@Test
public void testWebViewHandlesSuccess() {
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);
WebViewLoginMethodHandler handler = new WebViewLoginMethodHandler(mockLoginClient);
LoginClient.Request request = createRequest();
handler.onWebDialogComplete(request, bundle, null);
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 WebViewLoginMethodHandlerTest method testFromSSOWithExpiresLong.
@Test
public void testFromSSOWithExpiresLong() {
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", 60L);
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());
}
use of com.facebook.AccessToken in project facebook-android-sdk by facebook.
the class LoginClientTest method testReauthorizationWithSameFbidSucceeds.
@Test
public void testReauthorizationWithSameFbidSucceeds() throws Exception {
FacebookSdk.sdkInitialize(RuntimeEnvironment.application);
LoginClient.Request request = createRequest(ACCESS_TOKEN);
AccessToken token = new AccessToken(ACCESS_TOKEN, APP_ID, USER_ID, PERMISSIONS, null, null, null, null);
LoginClient.Result result = LoginClient.Result.createTokenResult(request, token);
LoginClient.OnCompletedListener listener = mock(LoginClient.OnCompletedListener.class);
LoginClient client = new LoginClient(mockFragment);
client.setOnCompletedListener(listener);
client.completeAndValidate(result);
ArgumentCaptor<LoginClient.Result> resultArgumentCaptor = ArgumentCaptor.forClass(LoginClient.Result.class);
verify(listener).onCompleted(resultArgumentCaptor.capture());
result = resultArgumentCaptor.getValue();
assertNotNull(result);
assertEquals(LoginClient.Result.Code.SUCCESS, result.code);
AccessToken resultToken = result.token;
assertNotNull(resultToken);
assertEquals(ACCESS_TOKEN, resultToken.getToken());
// We don't care about ordering.
assertEquals(PERMISSIONS, resultToken.getPermissions());
}
use of com.facebook.AccessToken in project facebook-android-sdk by facebook.
the class LoginManagerTest method testLogInWithPublishAndAccessTokenCreatesReauthRequest.
@Test
public void testLogInWithPublishAndAccessTokenCreatesReauthRequest() {
AccessToken accessToken = createAccessToken();
stub(method(AccessToken.class, "getCurrentAccessToken")).toReturn(accessToken);
LoginManager loginManager = new LoginManager();
loginManager.logInWithPublishPermissions(mockActivity, Arrays.asList("publish_actions", "publish_stream"));
int loginRequestCode = CallbackManagerImpl.RequestCodeOffset.Login.toRequestCode();
verify(mockActivity, times(1)).startActivityForResult(any(Intent.class), eq(loginRequestCode));
}
Aggregations