sendCustomChallengeAnswer method

Future<CognitoUserSession?> sendCustomChallengeAnswer(
  1. String answerChallenge, [
  2. Map<String, String>? validationData
])

This is used by the user once he has the responses to a custom challenge

Implementation

Future<CognitoUserSession?> sendCustomChallengeAnswer(String answerChallenge,
    [Map<String, String>? validationData]) async {
  final challengeResponses = {
    'USERNAME': username,
    'ANSWER': answerChallenge,
  };

  final authenticationHelper =
      AuthenticationHelper(pool.getUserPoolId().split('_')[1]);

  await getCachedDeviceKeyAndPassword();
  if (_deviceKey != null) {
    challengeResponses['DEVICE_KEY'] = _deviceKey;
  }

  if (_clientSecretHash != null) {
    challengeResponses['SECRET_HASH'] = _clientSecretHash;
  }

  final paramsReq = {
    'ChallengeName': 'CUSTOM_CHALLENGE',
    'ChallengeResponses': challengeResponses,
    'ClientId': pool.getClientId(),
    'ClientMetadata': validationData,
    'Session': _session,
  };

  if (getUserContextData() != null) {
    paramsReq['UserContextData'] = getUserContextData();
  }

  final data = await client!.request('RespondToAuthChallenge',
      await _analyticsMetadataParamsDecorator.call(paramsReq));

  return _authenticateUserInternal(data, authenticationHelper);
}