registrationTokenValidity method

Future<bool> registrationTokenValidity(
  1. String token
)

Queries the server to determine if a given registration token is still valid at the time of request. This is a point-in-time check where the token might still expire by the time it is used.

Servers should be sure to rate limit this endpoint to avoid brute force attacks.

token The token to check validity of.

returns valid: True if the token is still valid, false otherwise. This should additionally be false if the token is not a recognised token by the server.

Implementation

Future<bool> registrationTokenValidity(String token) async {
  final requestUri = Uri(
      path: '_matrix/client/v1/register/m.login.registration_token/validity',
      queryParameters: {
        'token': token,
      });
  final request = Request('GET', baseUri!.resolveUri(requestUri));
  final response = await httpClient.send(request);
  final responseBody = await response.stream.toBytes();
  if (response.statusCode != 200) unexpectedResponse(response, responseBody);
  final responseString = utf8.decode(responseBody);
  final json = jsonDecode(responseString);
  return json['valid'] as bool;
}