use of com.amazonaws.services.cognitoidentityprovider.model.ForgetDeviceRequest 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.services.cognitoidentityprovider.model.ForgetDeviceRequest 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.services.cognitoidentityprovider.model.ForgetDeviceRequest in project aws-sdk-android by aws-amplify.
the class CognitoDevice method forgetDeviceInternal.
/**
* Internal method to forget this device.
*
* @param session REQUIRED: A valid {@link CognitoUserSession}.
*/
private void forgetDeviceInternal(CognitoUserSession session) {
if (session != null && session.isValid()) {
if (this.deviceKey != null) {
final ForgetDeviceRequest forgetDeviceRequest = new ForgetDeviceRequest();
forgetDeviceRequest.setAccessToken(session.getAccessToken().getJWTToken());
forgetDeviceRequest.setDeviceKey(this.deviceKey);
user.getCognitoIdentityProviderClient().forgetDevice(forgetDeviceRequest);
} else {
throw new CognitoParameterInvalidException("Device key is null");
}
} else {
throw new CognitoNotAuthorizedException("User is not authorized");
}
}
use of com.amazonaws.services.cognitoidentityprovider.model.ForgetDeviceRequest in project aws-sdk-android by aws-amplify.
the class DeviceOperations method _forgetDevice.
private ReturningRunnable<Void> _forgetDevice(final String deviceKey) {
return new ReturningRunnable<Void>() {
@Override
public Void run() throws Exception {
CognitoDevice cognitoDevice = getCognitoDevice(deviceKey);
final ForgetDeviceRequest forgetDeviceRequest = new ForgetDeviceRequest().withAccessToken(mobileClient.getTokens().getAccessToken().getTokenString()).withDeviceKey(cognitoDevice.getDeviceKey());
userpoolLL.forgetDevice(forgetDeviceRequest);
return null;
}
};
}
Aggregations