use of com.facebook.AccessToken in project facebook-android-sdk by facebook.
the class GetTokenLoginMethodHandlerTest method testFromNativeLogin.
@Test
public void testFromNativeLogin() {
ArrayList<String> permissions = Utility.arrayList("stream_publish", "go_outside_and_play");
String token = "AnImaginaryTokenValue";
String userId = "1000";
long nowSeconds = new Date().getTime() / 1000;
Intent intent = new Intent();
intent.putExtra(NativeProtocol.EXTRA_ACCESS_TOKEN, token);
intent.putExtra(NativeProtocol.EXTRA_EXPIRES_SECONDS_SINCE_EPOCH, nowSeconds + 60L);
intent.putExtra(NativeProtocol.EXTRA_PERMISSIONS, permissions);
intent.putExtra(NativeProtocol.EXTRA_USER_ID, userId);
AccessToken accessToken = GetTokenLoginMethodHandler.createAccessTokenFromNativeLogin(intent.getExtras(), AccessTokenSource.FACEBOOK_APPLICATION_NATIVE, "1234");
TestUtils.assertSamePermissions(permissions, accessToken);
assertEquals(token, accessToken.getToken());
assertEquals(AccessTokenSource.FACEBOOK_APPLICATION_NATIVE, accessToken.getSource());
assertTrue(!accessToken.isExpired());
}
use of com.facebook.AccessToken in project facebook-android-sdk by facebook.
the class KatanaProxyLoginMethodHandlerTest method testProxyAuthHandlesSuccess.
@Test
public void testProxyAuthHandlesSuccess() {
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);
KatanaProxyLoginMethodHandler handler = new KatanaProxyLoginMethodHandler(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 react-native-fbsdk by facebook.
the class RCTLoginButton method init.
public void init() {
mAccessTokenTracker = new AccessTokenTracker() {
@Override
protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken currentAccessToken) {
if (currentAccessToken == null) {
WritableMap event = Arguments.createMap();
event.putString("type", "logoutFinished");
ReactContext context = (ReactContext) getContext();
context.getJSModule(RCTEventEmitter.class).receiveEvent(getId(), "topChange", event);
}
}
};
this.registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
WritableMap event = Arguments.createMap();
event.putString("type", "loginFinished");
event.putString("error", null);
WritableMap result = Arguments.createMap();
result.putBoolean("isCancelled", false);
result.putArray("grantedPermissions", Arguments.fromJavaArgs(setToStringArray(loginResult.getRecentlyGrantedPermissions())));
result.putArray("declinedPermissions", Arguments.fromJavaArgs(setToStringArray(loginResult.getRecentlyDeniedPermissions())));
event.putMap("result", result);
ReactContext context = (ReactContext) getContext();
context.getJSModule(RCTEventEmitter.class).receiveEvent(getId(), "topChange", event);
}
@Override
public void onError(FacebookException error) {
WritableMap event = Arguments.createMap();
event.putString("type", "loginFinished");
event.putString("error", error.toString());
WritableMap result = Arguments.createMap();
result.putBoolean("isCancelled", false);
event.putMap("result", result);
ReactContext context = (ReactContext) getContext();
context.getJSModule(RCTEventEmitter.class).receiveEvent(getId(), "topChange", event);
}
@Override
public void onCancel() {
WritableMap event = Arguments.createMap();
event.putString("type", "loginFinished");
event.putString("error", null);
WritableMap result = Arguments.createMap();
result.putBoolean("isCancelled", true);
event.putMap("result", result);
ReactContext context = (ReactContext) getContext();
context.getJSModule(RCTEventEmitter.class).receiveEvent(getId(), "topChange", event);
}
});
}
use of com.facebook.AccessToken in project react-native-fbsdk by facebook.
the class Utility method buildAccessToken.
public static AccessToken buildAccessToken(ReadableMap accessTokenMap) {
AccessTokenSource accessTokenSource = AccessTokenSource.valueOf(accessTokenMap.getString("accessTokenSource"));
Date expirationTime = new Date((long) accessTokenMap.getDouble("expirationTime"));
Date lastRefreshTime = new Date((long) accessTokenMap.getDouble("lastRefreshTime"));
return new AccessToken(accessTokenMap.getString("accessToken"), accessTokenMap.getString("applicationID"), accessTokenMap.getString("userID"), reactArrayToStringList(accessTokenMap.getArray("permissions")), reactArrayToStringList(accessTokenMap.getArray("declinedPermissions")), accessTokenSource, expirationTime, lastRefreshTime);
}
use of com.facebook.AccessToken in project react-native-fbsdk by facebook.
the class FBAccessTokenModule method setCurrentAccessToken.
/**
* Set {@link AccessToken} for the current session.
* @param accessTokenMap must satisfy the requirements in
* <a href="https://developers.facebook.com/docs/reference/android/current/class/AccessToken/">
* Facebook AccessToken</a>
*/
@ReactMethod
public void setCurrentAccessToken(ReadableMap accessTokenMap) {
AccessToken accessToken = Utility.buildAccessToken(accessTokenMap);
AccessToken.setCurrentAccessToken(accessToken);
}
Aggregations