bind3PID method

Future<void> bind3PID(
  1. String clientSecret,
  2. String idAccessToken,
  3. String idServer,
  4. String sid,
)
inherited

Binds a 3PID to the user's account through the specified identity server.

Nodes should not prevent this request from succeeding if another user has bound the 3PID. Nodes should simply proxy any errors received by the identity server to the caller.

Nodes should track successful binds so they can be unbound later.

clientSecret The client secret used in the session with the identity server.

idAccessToken An access token previously registered with the identity server.

idServer The identity server to use.

sid The session identifier given by the identity server.

Implementation

Future<void> bind3PID(String clientSecret, String idAccessToken,
    String idServer, String sid) async {
  final requestUri = Uri(path: '_api/client/v3/account/3pid/bind');
  final request = Request('POST', baseUri!.resolveUri(requestUri));
  request.headers['authorization'] = 'Bearer ${bearerToken!}';
  request.headers['content-type'] = 'application/json';
  request.bodyBytes = utf8.encode(jsonEncode({
    'client_secret': clientSecret,
    'id_access_token': idAccessToken,
    'id_server': idServer,
    'sid': sid,
  }));
  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 ignore(json);
}