Example usage for com.amazonaws.services.cognitoidp.model RespondToAuthChallengeResult getChallengeName

List of usage examples for com.amazonaws.services.cognitoidp.model RespondToAuthChallengeResult getChallengeName

Introduction

In this page you can find the example usage for com.amazonaws.services.cognitoidp.model RespondToAuthChallengeResult getChallengeName.

Prototype


public String getChallengeName() 

Source Link

Document

The challenge name.

Usage

From source file:io.fineo.client.auth.cognito.CognitoUser.java

License:Open Source License

/**
 * Responds to an MFA challenge. This method creates a response to the challenge and calls the
 * internal method to respond to the authentication challenge.
 *
 * @param mfaCode                   REQUIRED: The MFA code received by the user.
 * @param challenge                 REQUIRED: Current challenge {@link RespondToAuthChallengeResult}.
 * @param callback                  REQUIRED: {@link AuthenticationHandler} callback.
 * @return {@link Runnable} for the next step in user authentication.
 *///w  w w .  j a v a 2  s. c o  m
public Runnable respondToMfaChallenge(final String mfaCode, final RespondToAuthChallengeResult challenge,
        final AuthenticationHandler callback, final boolean runInBackground) {
    final RespondToAuthChallengeRequest challengeResponse = new RespondToAuthChallengeRequest();
    Map<String, String> mfaParameters = new HashMap<String, String>();
    mfaParameters.put("SMS_MFA_CODE", mfaCode);
    mfaParameters.put("USERNAME", usernameInternal);
    mfaParameters.put("DEVICE_KEY", deviceKey);
    mfaParameters.put("SECRET_HASH", secretHash);
    challengeResponse.setClientId(clientId);
    challengeResponse.setSession(challenge.getSession());
    challengeResponse.setChallengeName(challenge.getChallengeName());
    challengeResponse.setChallengeResponses(mfaParameters);
    return respondToChallenge(challengeResponse, callback, runInBackground);
}

From source file:io.fineo.client.auth.cognito.CognitoUser.java

License:Open Source License

/**
 * Find the next step from the challenge.
 * This is an important step in the generic authentication flow. After the responding to a challenge,
 * the results are analyzed here to determine the next step in the authentication process.
 * Like all other methods in this SDK, this is designed to work with Continuation objects.
 * This method returns a {@link Runnable} with the code to be executed, for the next step, to the invoking Continuation.
 * The possible steps are/*from ww  w .j a va2  s . c om*/
 *  1) Authentication was successful and we have the tokens, in this case we call {@code onSuccess()} to return the tokens.
 *  2) User password is required, an AuthenticationContinuation is created.
 *  3) MFA validation is required, a MultiFactorAuthenticationContinuation object is created.
 *  4) Other generic challenge, the challenge details are passed to the user.
 *
 * @param challenge                 REQUIRED: Current challenge details, {@link RespondToAuthChallengeResult}.
 * @param callback                  REQUIRED: {@link AuthenticationDetails} callback.
 * @param runInBackground           REQUIRED: Boolean to indicate the current threading.
 * @return {@link Runnable} for the next step in user authentication.
 */
private Runnable handleChallenge(final RespondToAuthChallengeResult challenge,
        final AuthenticationHandler callback, final boolean runInBackground) {
    Runnable nextTask;
    final CognitoUser cognitoUser = this;
    nextTask = new Runnable() {
        @Override
        public void run() {
            callback.onFailure(
                    new CognitoInternalErrorException("Authentication failed due to an internal error"));
        }
    };

    if (challenge == null) {
        return nextTask;
    }

    updateInternalUsername(challenge.getChallengeParameters());
    String challengeName = challenge.getChallengeName();
    if (challengeName == null) {
        LOG.debug("Got challenge: {}", challenge);
        final CognitoUserSession cognitoUserSession = getCognitoUserSession(
                challenge.getAuthenticationResult());
        cacheTokens(cognitoUserSession);
        NewDeviceMetadataType newDeviceMetadata = challenge.getAuthenticationResult().getNewDeviceMetadata();
        if (newDeviceMetadata == null) {
            nextTask = new Runnable() {
                @Override
                public void run() {
                    callback.onSuccess(cognitoUserSession, null);
                }
            };
        } else {
            ConfirmDeviceResult confirmDeviceResult = confirmDevice(newDeviceMetadata);
            if (confirmDeviceResult != null && confirmDeviceResult.isUserConfirmationNecessary()) {
                final CognitoDevice newDevice = new CognitoDevice(newDeviceMetadata.getDeviceKey(), null, null,
                        null, null, cognitoUser);
                nextTask = new Runnable() {
                    @Override
                    public void run() {
                        callback.onSuccess(cognitoUserSession, newDevice);
                    }
                };
            } else {
                nextTask = new Runnable() {
                    @Override
                    public void run() {
                        callback.onSuccess(cognitoUserSession, null);
                    }
                };
            }
        }
    } else if (challengeName.equals("PASSWORD_VERIFIER")) {
        return nextTask;
    } else if (challengeName.equals("SMS_MFA")) {
        throw new UnsupportedOperationException("MFA challenges not supported!");
    } else if (challengeName.equals("DEVICE_SRP_AUTH")) {
        nextTask = deviceSrpAuthentication(challenge, callback, runInBackground);
    } else {
        throw new RuntimeException("Generic challenge continuation no supported!");
        //            final ChallengeContinuation challengeContinuation =
        //                    new ChallengeContinuation(cognitoUser, context, clientId, challenge, runInBackground, callback);
        //            nextTask = new Runnable() {
        //                @Override
        //                public void run() {
        //                    callback.authenticationChallenge(challengeContinuation);
        //                }
        //            };
    }
    return nextTask;
}