sendSignedChallengeTransaction method

Future<String> sendSignedChallengeTransaction(
  1. String base64EnvelopeXDR
)

Sends the signed challenge transaction back to the web auth server to obtain the jwt token. In case of success, it returns the jwt token obtained from the web auth server.

Implementation

Future<String> sendSignedChallengeTransaction(
    String base64EnvelopeXDR) async {
  Uri serverURI = Uri.parse(_authEndpoint);

  Map<String, String> headers = {...RequestBuilder.headers};
  headers.putIfAbsent("Content-Type", () => "application/json");

  SubmitCompletedChallengeResponse result = await httpClient
      .post(serverURI,
          body: json.encode({"transaction": base64EnvelopeXDR}),
          headers: headers)
      .then((response) {
    SubmitCompletedChallengeResponse submitTransactionResponse;
    switch (response.statusCode) {
      case 200:
      case 400:
        submitTransactionResponse = SubmitCompletedChallengeResponse.fromJson(
            json.decode(response.body));
        break;
      case 504:
        throw new SubmitCompletedChallengeTimeoutResponseException();
      default:
        throw new SubmitCompletedChallengeUnknownResponseException(
            response.statusCode, response.body);
    }
    return submitTransactionResponse;
  }).catchError((onError) {
    throw onError;
  });

  if (result.error != null) {
    throw SubmitCompletedChallengeErrorResponseException(result.error!);
  }

  return result.jwtToken!;
}