use of com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GenericHandler in project aws-sdk-android by aws-amplify.
the class CognitoIdentityProviderDevicesTest method forgetDeviceInCurrentThread.
@Test
public void forgetDeviceInCurrentThread() {
CognitoDeviceHelper.cacheDeviceKey(TEST_USER_NAME, TEST_USER_POOL, TEST_DEVICE_KEY, appContext);
testUser = testPool.getUser(TEST_USER_NAME);
// Store tokens in shared preferences
final String testAccessToken = getValidJWT(3600L);
awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "idToken", getValidJWT(3600L));
awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "accessToken", testAccessToken);
awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "refreshToken", TEST_CACHED_RTOKEN);
// Set mock result for the change password request API call
doNothing().when(mockCSIClient).forgetDevice(any(ForgetDeviceRequest.class));
final CountDownLatch countDownLatch = new CountDownLatch(1);
CognitoDevice cachedDevice = testUser.thisDevice();
cachedDevice.forgetDevice(new GenericHandler() {
@Override
public void onSuccess() {
ArgumentCaptor<ForgetDeviceRequest> argumentCaptor = ArgumentCaptor.forClass(ForgetDeviceRequest.class);
verify(mockCSIClient).forgetDevice(argumentCaptor.capture());
ForgetDeviceRequest requestSent = argumentCaptor.getValue();
Log.d(TAG, "testAccessToken = " + testAccessToken);
Log.d(TAG, "requestSent.getAccessToken() = " + requestSent.getAccessToken());
assertEquals(testAccessToken, requestSent.getAccessToken());
countDownLatch.countDown();
}
@Override
public void onFailure(Exception exception) {
assertNotNull(exception);
countDownLatch.countDown();
}
});
try {
countDownLatch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
use of com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GenericHandler in project aws-sdk-android by aws-amplify.
the class CognitoIdentityProviderDevicesTest method getDeviceDetailsInCurrentThread.
@Test
public void getDeviceDetailsInCurrentThread() {
CognitoDeviceHelper.cacheDeviceKey(TEST_USER_NAME, TEST_USER_POOL, TEST_DEVICE_KEY, appContext);
testUser = testPool.getUser(TEST_USER_NAME);
// Store tokens in shared preferences
final String testAccessToken = getValidJWT(3600L);
awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + ".idToken", getValidJWT(3600L));
awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "accessToken", testAccessToken);
awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "refreshToken", TEST_CACHED_RTOKEN);
// Set mock result for the change password request API call
doReturn(TEST_VALID_GET_DEVICE_RESPONSE).when(mockCSIClient).getDevice(any(GetDeviceRequest.class));
CognitoDevice cachedDevice = testUser.thisDevice();
cachedDevice.getDevice(new GenericHandler() {
@Override
public void onSuccess() {
ArgumentCaptor<GetDeviceRequest> argumentCaptor = ArgumentCaptor.forClass(GetDeviceRequest.class);
verify(mockCSIClient).getDevice(argumentCaptor.capture());
GetDeviceRequest requestSent = argumentCaptor.getValue();
assertEquals(testAccessToken, requestSent.getAccessToken());
}
@Override
public void onFailure(Exception exception) {
assertNotNull(exception);
}
});
}
use of com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GenericHandler in project aws-sdk-android by aws-amplify.
the class CognitoIdentityProviderDevicesTest method forgetDeviceInBackgroundThread.
@Test
public void forgetDeviceInBackgroundThread() {
CognitoDeviceHelper.cacheDeviceKey(TEST_USER_NAME, TEST_USER_POOL, TEST_DEVICE_KEY, appContext);
testUser = testPool.getUser(TEST_USER_NAME);
// Store tokens in shared preferences
final String testAccessToken = getValidJWT(3600L);
awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "idToken", getValidJWT(3600L));
awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "accessToken", testAccessToken);
awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "refreshToken", TEST_CACHED_RTOKEN);
// Set mock result for the change password request API call
doNothing().when(mockCSIClient).forgetDevice(any(ForgetDeviceRequest.class));
CognitoDevice cachedDevice = testUser.thisDevice();
cachedDevice.forgetDeviceInBackground(new GenericHandler() {
@Override
public void onSuccess() {
ArgumentCaptor<ForgetDeviceRequest> argumentCaptor = ArgumentCaptor.forClass(ForgetDeviceRequest.class);
verify(mockCSIClient).forgetDevice(argumentCaptor.capture());
ForgetDeviceRequest requestSent = argumentCaptor.getValue();
assertEquals(testAccessToken, requestSent.getAccessToken());
}
@Override
public void onFailure(Exception exception) {
assertNotNull(exception);
}
});
}
use of com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GenericHandler in project aws-sdk-android by aws-amplify.
the class CognitoDevice method doNotRememberThisDeviceInBackground.
/**
* Marks this device as <b>not</b> trusted, runs in a background thread.
*
* @param callback REQUIRED: {@link GenericHandler} callback.
*/
public void doNotRememberThisDeviceInBackground(final GenericHandler callback) {
if (callback == null) {
throw new CognitoParameterInvalidException("callback is null");
}
new Thread(new Runnable() {
@Override
public void run() {
final Handler handler = new Handler(context.getMainLooper());
Runnable returnCallback;
try {
updateDeviceStatusInternal(user.getCachedSession(), DEVICE_TYPE_NOT_REMEMBERED);
returnCallback = new Runnable() {
@Override
public void run() {
callback.onSuccess();
}
};
} catch (final Exception e) {
returnCallback = new Runnable() {
@Override
public void run() {
callback.onFailure(e);
}
};
}
handler.post(returnCallback);
}
}).start();
}
use of com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GenericHandler in project aws-sdk-android by aws-amplify.
the class CognitoUser method verifyAttributeInBackground.
/**
* Verify an attribute with the verification code, in background.
* <p>
* Call this method to verify an attribute with the "verification code". To
* request for a "verification code" call the method
* {@link CognitoUser#getAttributeVerificationCodeInBackground(String, VerificationHandler)}
* .
* </p>
*
* @param attributeName REQUIRED: The attribute that is being verified.
* @param verificationCode REQUIRED: The code for verification.
* @param callback REQUIRED: Callback
*/
public void verifyAttributeInBackground(final String attributeName, final String verificationCode, final GenericHandler callback) {
if (callback == null) {
throw new CognitoParameterInvalidException("callback is null");
}
final CognitoUser user = this;
new Thread(new Runnable() {
@Override
public void run() {
final Handler handler = new Handler(context.getMainLooper());
Runnable returnCallback;
try {
final CognitoUserSession session = user.getCachedSession();
verifyAttributeInternal(attributeName, verificationCode, session);
returnCallback = new Runnable() {
@Override
public void run() {
callback.onSuccess();
}
};
} catch (final Exception e) {
returnCallback = new Runnable() {
@Override
public void run() {
callback.onFailure(e);
}
};
}
handler.post(returnCallback);
}
}).start();
}
Aggregations