queryUserByProtocol method

Future<List<ThirdPartyUser>> queryUserByProtocol(
  1. String protocol, {
  2. Map<String, String>? fields,
})

Retrieve a Matrix User ID linked to a user on the third-party service, given a set of user parameters.

protocol The name of the protocol.

fields One or more custom fields that are passed to the AS to help identify the user.

Implementation

Future<List<ThirdPartyUser>> queryUserByProtocol(
  String protocol, {
  Map<String, String>? fields,
}) async {
  final requestUri = Uri(
    path:
        '_matrix/client/v3/thirdparty/user/${Uri.encodeComponent(protocol)}',
    queryParameters: {
      if (fields != null) ...fields,
    },
  );
  final request = Request('GET', baseUri!.resolveUri(requestUri));
  request.headers['authorization'] = 'Bearer ${bearerToken!}';
  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 as List)
      .map((v) => ThirdPartyUser.fromJson(v as Map<String, Object?>))
      .toList();
}