use of com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.ForgotPasswordHandler in project aws-sdk-android by aws-amplify.
the class CognitoUser method forgotPasswordInBackground.
/**
* Starts the process to set a new password for forgotten password case, in
* background.
* <p>
* This will initiate the process to set a new password when the current
* password is forgotten. The new password will be successfully set only
* after the verification code, sent to the registered email or phone number
* of the user, successfully verified by Cognito Identity Provider service.
* This method will pass a continuation object to the callback. Use setters
* in the Continuation object {@link ForgotPasswordContinuation} to set the
* new password and verification code and call continue on the continuation
* object, {@code CognitoIdentityProviderContinuation.continueTask()}.
* </p>
*
* @param clientMetadata A map of custom key-value pairs that is passed to the lambda function for
* lambda functions triggered by forgot password.
* @param callback REQUIRED: {@link ForgotPasswordHandler} callback
*/
public void forgotPasswordInBackground(final Map<String, String> clientMetadata, final ForgotPasswordHandler callback) {
if (callback == null) {
throw new CognitoParameterInvalidException("callback is null");
}
final CognitoUser cognitoUser = this;
new Thread(new Runnable() {
@Override
public void run() {
final Handler handler = new Handler(context.getMainLooper());
Runnable returnCallback;
try {
final ForgotPasswordResult forgotPasswordResult = forgotPasswordInternal(clientMetadata);
final ForgotPasswordContinuation continuation = new ForgotPasswordContinuation(cognitoUser, new CognitoUserCodeDeliveryDetails(forgotPasswordResult.getCodeDeliveryDetails()), ForgotPasswordContinuation.RUN_IN_BACKGROUND, callback);
returnCallback = new Runnable() {
@Override
public void run() {
callback.getResetCode(continuation);
}
};
} 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.ForgotPasswordHandler in project aws-sdk-android by aws-amplify.
the class CognitoUser method confirmPasswordInBackground.
/**
* Set new password and send verification code to Cognito Identity Provider
* service, in background.
* <p>
* This method will be called by {@link ForgotPasswordContinuation}
* continuation object.
* </p>
*
* @param verificationCode REQUIRED: Code sent from Cognito Identity
* Provider Service.
* @param newPassword REQUIRED: New password. On successful verification of
* {@code verificationCode}, this will be the new password for
* this user.
* @param clientMetadata A map of custom key-value pairs that you can provide as input for any
* custom workflows triggered by confirm password.
* @param callback REQUIRED: {@link ForgotPasswordHandler} callback.
*/
public void confirmPasswordInBackground(final String verificationCode, final String newPassword, final Map<String, String> clientMetadata, final ForgotPasswordHandler 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 {
confirmPasswordInternal(verificationCode, newPassword, 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.ForgotPasswordHandler in project aws-sdk-android by aws-amplify.
the class OAuth2Utils method _forgotPassword.
private Runnable _forgotPassword(final String username, final Map<String, String> clientMetadata, final Callback<ForgotPasswordResult> callback) {
return new Runnable() {
@Override
public void run() {
forgotPasswordCallback = new InternalCallback<ForgotPasswordResult>(callback);
userpool.getUser(username).forgotPasswordInBackground(clientMetadata, new ForgotPasswordHandler() {
@Override
public void onSuccess() {
forgotPasswordCallback.onResult(new ForgotPasswordResult(ForgotPasswordState.DONE));
}
@Override
public void getResetCode(ForgotPasswordContinuation continuation) {
forgotPasswordContinuation = continuation;
ForgotPasswordResult result = new ForgotPasswordResult(ForgotPasswordState.CONFIRMATION_CODE);
CognitoUserCodeDeliveryDetails parameters = continuation.getParameters();
result.setParameters(new UserCodeDeliveryDetails(parameters.getDestination(), parameters.getDeliveryMedium(), parameters.getAttributeName()));
forgotPasswordCallback.onResult(result);
}
@Override
public void onFailure(Exception exception) {
forgotPasswordCallback.onError(exception);
}
});
}
};
}
Aggregations