Search in sources :

Example 1 with OAuthToken

use of com.fitpay.android.api.models.security.OAuthToken in project fitpay-android-sdk by fitpay.

the class TestActions method doLogin.

protected boolean doLogin(LoginIdentity loginIdentity) throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    ResultProvidingCallback<OAuthToken> callback = new ResultProvidingCallback<>(latch);
    ApiManager.getInstance().loginUser(loginIdentity, callback);
    boolean completed = latch.await(TIMEOUT, TimeUnit.SECONDS);
    assertTrue("login did not complete successfully", completed);
    assertEquals("login error code. (message: " + callback.getErrorMessage() + ")", -1, callback.getErrorCode());
    return completed;
}
Also used : OAuthToken(com.fitpay.android.api.models.security.OAuthToken) ResultProvidingCallback(com.fitpay.android.api.callbacks.ResultProvidingCallback) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 2 with OAuthToken

use of com.fitpay.android.api.models.security.OAuthToken in project fitpay-android-sdk by fitpay.

the class WebViewCommunicatorImpl method sendUserData.

@Override
@JavascriptInterface
public void sendUserData(String callbackId, String deviceId, String token, String userId) {
    this.deviceId = deviceId;
    FPLog.d(TAG, "sendUserData received data: deviceId: " + deviceId + ", token: " + token + ", userId: " + userId);
    OAuthToken oAuthToken = new OAuthToken.Builder().accessToken(token).build();
    ApiManager.getInstance().setAuthToken(oAuthToken);
    getUserAndDevice(deviceId, callbackId);
}
Also used : OAuthToken(com.fitpay.android.api.models.security.OAuthToken) JavascriptInterface(android.webkit.JavascriptInterface)

Example 3 with OAuthToken

use of com.fitpay.android.api.models.security.OAuthToken in project fitpay-android-sdk by fitpay.

the class UserTest2 method testCantLoginWithDifferentPassword.

@Test
// this test does not work in demo environment since does auto-login
@Ignore
public void testCantLoginWithDifferentPassword() throws Exception {
    this.user = getUser();
    assertNotNull(user);
    LoginIdentity badCredentials = getTestLoginIdentity(userName, TestUtils.getRandomLengthNumber(4, 4));
    final CountDownLatch latch = new CountDownLatch(1);
    ResultProvidingCallback<OAuthToken> callback = new ResultProvidingCallback<>(latch);
    ApiManager.getInstance().loginUser(badCredentials, callback);
    boolean completed = latch.await(TIMEOUT, TimeUnit.SECONDS);
    assertTrue("login did not complete successfully", completed);
    assertEquals("login error code. (message: " + callback.getErrorMessage() + ")", 401, callback.getErrorCode());
}
Also used : OAuthToken(com.fitpay.android.api.models.security.OAuthToken) ResultProvidingCallback(com.fitpay.android.api.callbacks.ResultProvidingCallback) CountDownLatch(java.util.concurrent.CountDownLatch) LoginIdentity(com.fitpay.android.api.models.user.LoginIdentity) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with OAuthToken

use of com.fitpay.android.api.models.security.OAuthToken in project fitpay-android-sdk by fitpay.

the class Steps method login.

public void login() throws InterruptedException {
    final CountDownLatch latch = new CountDownLatch(1);
    final boolean[] isRequestSuccess = { false };
    LoginIdentity loginIdentity = null;
    try {
        loginIdentity = new LoginIdentity.Builder().setUsername(userName).setPassword(password).build();
    } catch (ValidationException ignored) {
    }
    Assert.assertNotNull(loginIdentity);
    ApiManager.getInstance().loginUser(loginIdentity, new ApiCallback<OAuthToken>() {

        @Override
        public void onSuccess(OAuthToken result) {
            Assert.assertNotNull("missing bearer token", result.getAccessToken());
            isRequestSuccess[0] = true;
            latch.countDown();
        }

        @Override
        public void onFailure(@ResultCode.Code int errorCode, String errorMessage) {
            fail("unable to login: " + errorMessage);
            latch.countDown();
        }
    });
    latch.await(TIMEOUT, TimeUnit.SECONDS);
    Assert.assertTrue(isRequestSuccess[0]);
}
Also used : OAuthToken(com.fitpay.android.api.models.security.OAuthToken) ValidationException(com.fitpay.android.utils.ValidationException) CountDownLatch(java.util.concurrent.CountDownLatch) LoginIdentity(com.fitpay.android.api.models.user.LoginIdentity)

Example 5 with OAuthToken

use of com.fitpay.android.api.models.security.OAuthToken in project fitpay-android-sdk by fitpay.

the class BearerTokenTest method testExpiredToken.

@Test
public void testExpiredToken() throws Exception {
    OAuthToken token = new OAuthToken.Builder().accessToken("eyJhbGciOiJSUzI1NiJ9.eyJqdGkiOiI0MmMwOWY5YS1mYWRmLTQyZDUtO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Da4_jW_1gI9BKDX8UXAEICaELasQRv4fgG0zGcua-f-FJJywtkvLc3PEaZP2xN8wpcUL053jg2QaNjgGWH_YWN3krj43gnAcgt9rOVZlTJKSGpED0Np4bq8IHZa6FBh-aFG0OzO3VWilMHiwFDLTEIlgrfVvV5-7_JKXDDDgy9ukbtmbzth1xPVBVNlxKS7K6tSlvttJ3esRuYMUqw").build();
    ApiManager.getInstance().setAuthToken(token);
    CountDownLatch latch = new CountDownLatch(1);
    final List<Integer> codes = new ArrayList<>();
    ApiManager.getInstance().getUser(new ApiCallback<User>() {

        @Override
        public void onSuccess(User result) {
            codes.add(200);
            latch.countDown();
        }

        @Override
        public void onFailure(@ResultCode.Code int errorCode, String errorMessage) {
            System.out.println(errorMessage);
            codes.add(errorCode);
            latch.countDown();
        }
    });
    latch.await();
    Assert.assertEquals("incorrect number for response codes captured", 1, codes.size());
    Assert.assertEquals(new Integer(AccessDenied.INVALID_TOKEN_RESPONSE_CODE), codes.get(0));
    // EXPIRED_TOKEN will be received only once after commit: limited the number of expired token events (#156)
    Assert.assertEquals("access denied not posted to RxBus", 2, listener.getReceived().size());
    // key setup
    Assert.assertEquals(AccessDenied.Reason.EXPIRED_TOKEN, listener.getReceived().get(0).getReason());
    // Assert.assertEquals(AccessDenied.Reason.EXPIRED_TOKEN, listener.getReceived().get(1).getReason()); // getting user
    // denied get user
    Assert.assertEquals(AccessDenied.Reason.UNAUTHORIZED, listener.getReceived().get(1).getReason());
}
Also used : OAuthToken(com.fitpay.android.api.models.security.OAuthToken) User(com.fitpay.android.api.models.user.User) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

OAuthToken (com.fitpay.android.api.models.security.OAuthToken)5 CountDownLatch (java.util.concurrent.CountDownLatch)4 ResultProvidingCallback (com.fitpay.android.api.callbacks.ResultProvidingCallback)2 LoginIdentity (com.fitpay.android.api.models.user.LoginIdentity)2 Test (org.junit.Test)2 JavascriptInterface (android.webkit.JavascriptInterface)1 User (com.fitpay.android.api.models.user.User)1 ValidationException (com.fitpay.android.utils.ValidationException)1 ArrayList (java.util.ArrayList)1 Ignore (org.junit.Ignore)1