answerSecurityChallenges function

Future<bool> answerSecurityChallenges(
  1. AccessToken accessToken,
  2. List<SecurityChallenge> answers
)

Allows an authenticated user to verify their location by answering their security questions. You can get the security challenges through getSecurityChallenges. Also check if this is needed using areSecurityChallengesNeeded.

Implementation

Future<bool> answerSecurityChallenges(
    AccessToken accessToken, List<SecurityChallenge> answers) async {
  /// Verify we have enough answers passed.
  if (answers.length != 3) {
    throw ArgumentError.value(
        answers, 'answers', 'We require at least 3 answers.');
  }

  final headers = {
    'authorization': 'Bearer $accessToken',
    'content-type': 'application/json',
  };
  final body = [for (final answer in answers) answer.asAnswerJson];
  final response = await requestBody(
      http.post, _mojangApi, 'user/security/location', body,
      headers: headers);
  if (response.statusCode == 403) {
    throw ArgumentError.value(
        answers, 'answers', 'At least one answer was incorrect.');
  }
  return response.statusCode == 204;
}