use of com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GenericHandler in project aws-sdk-android by aws-amplify.
the class CognitoUser method confirmSignUpInBackground.
/**
* Confirms user registration in background.
* <p>
* Confirming a user is required to complete the user's registration. Any
* other operations on a user. are possible only after registration
* confirmation.
* </p>
*
* @param confirmationCode REQUIRED: Code sent to the phone-number or email
* used to register the user.
* @param forcedAliasCreation REQUIRED: This flag indicates if the
* confirmation should go-through in case of parameter
* contentions.
* @param clientMetadata A map of custom key-value pairs that is passed to the lambda function for
* custom workflow.
* @param callback REQUIRED: This is a reference to {@link GenericHandler}
* callback handler.
*/
public void confirmSignUpInBackground(final String confirmationCode, final boolean forcedAliasCreation, final Map<String, String> clientMetadata, 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 {
confirmSignUpInternal(confirmationCode, forcedAliasCreation, clientMetadata);
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 deleteUserInBackground.
/**
* Deletes this user, in background.
*
* @param callback REQUIRED: @link GenericHandler} callback.
*/
public void deleteUserInBackground(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();
deleteUserInternal(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();
}
use of com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GenericHandler in project aws-sdk-android by aws-amplify.
the class CognitoIdentityProviderChangePasswordInstrumentedTest method changePasswordInBackgroundWithExpiredCachedTokensException.
@Test
public void changePasswordInBackgroundWithExpiredCachedTokensException() throws Exception {
testUser = testPool.getUser(TEST_USER_NAME);
// Set mock result for the change password request API call
InvalidParameterException exception = new InvalidParameterException("password change request failed");
doThrow(exception).when(mockCSIClient).changePassword(any(ChangePasswordRequest.class));
// Store tokens in shared preferences
SharedPreferences sharedPreferences = appContext.getSharedPreferences("CognitoIdentityProviderCache", Context.MODE_PRIVATE);
awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "idToken", getValidJWT(-3600L));
awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "accessToken", getValidJWT(-3600L));
awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "refreshToken", TEST_CACHED_RTOKEN);
final FlowTracker tracker = new FlowTracker("onFailure");
tracker.activate();
testUser.changePasswordInBackground(TEST_USER_PASSWORD, TEST_USER_NEW_PASS, new GenericHandler() {
@Override
public void onSuccess() {
assertTrue(tracker.check("onSuccess"));
}
@Override
public void onFailure(Exception exception) {
assertTrue(tracker.check("onFailure"));
assertNotNull(exception);
}
});
}
use of com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GenericHandler in project aws-sdk-android by aws-amplify.
the class CognitoIdentityProviderChangePasswordInstrumentedTest method changePasswordInCurrentWithExpiredCachedTokensException.
@Test
public void changePasswordInCurrentWithExpiredCachedTokensException() throws Exception {
testUser = testPool.getUser(TEST_USER_NAME);
// Set mock result for the change password request API call
InvalidParameterException exception = new InvalidParameterException("password change request failed");
doThrow(exception).when(mockCSIClient).changePassword(any(ChangePasswordRequest.class));
// Store tokens in shared preferences
SharedPreferences sharedPreferences = appContext.getSharedPreferences("CognitoIdentityProviderCache", Context.MODE_PRIVATE);
awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "idToken", getValidJWT(-3600L));
awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "accessToken", getValidJWT(-3600L));
awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "refreshToken", TEST_CACHED_RTOKEN);
final FlowTracker tracker = new FlowTracker("onFailure");
tracker.activate();
testUser.changePasswordInBackground(TEST_USER_PASSWORD, TEST_USER_NEW_PASS, new GenericHandler() {
@Override
public void onSuccess() {
assertTrue(tracker.check("onSuccess"));
}
@Override
public void onFailure(Exception exception) {
assertTrue(tracker.check("onFailure"));
assertNotNull(exception);
}
});
}
use of com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GenericHandler in project aws-sdk-android by aws-amplify.
the class CognitoIdentityProviderDevicesTest method trustDeviceInBackground.
@Test
public void trustDeviceInBackground() {
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.rememberThisDeviceInBackground(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);
}
});
}
Aggregations