use of com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GenericHandler in project aws-sdk-android by aws-amplify.
the class CognitoIdentityProviderDevicesTest method trustDeviceInCurrentThread.
@Test
public void trustDeviceInCurrentThread() {
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_UPDATE_DEVICE_RESPONSE).when(mockCSIClient).updateDeviceStatus(any(UpdateDeviceStatusRequest.class));
CognitoDevice cachedDevice = testUser.thisDevice();
cachedDevice.rememberThisDevice(new GenericHandler() {
@Override
public void onSuccess() {
ArgumentCaptor<UpdateDeviceStatusRequest> argumentCaptor = ArgumentCaptor.forClass(UpdateDeviceStatusRequest.class);
verify(mockCSIClient).updateDeviceStatus(argumentCaptor.capture());
UpdateDeviceStatusRequest 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 getDeviceDetailsInBackgroundThread.
@Test
public void getDeviceDetailsInBackgroundThread() {
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.getDeviceInBackground(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 CognitoDevice method forgetDeviceInBackground.
/**
* Stops tracking this device, runs in a background thread.
*
* @param callback REQUIRED: {@link GenericHandler} callback.
*/
public void forgetDeviceInBackground(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 {
forgetDeviceInternal(user.getCachedSession());
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 CognitoDevice method getDeviceInBackground.
/**
* Fetches device properties. Call this method to ensure the device properties are current.
* Reading device properties from this object can return null values.
*
* @param callback REQUIRED: {@link GenericHandler} callback.
*/
public void getDeviceInBackground(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 {
final GetDeviceResult getDeviceResult = getDeviceInternal(user.getCachedSession());
updateThis(getDeviceResult.getDevice());
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 CognitoDevice method rememberThisDeviceInBackground.
/**
* Marks this device as trusted, runs in a background.
*
* @param callback REQUIRED: {@link GenericHandler} callback.
*/
public void rememberThisDeviceInBackground(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_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();
}
Aggregations