add3PID method

Future<void> add3PID(
  1. String clientSecret,
  2. String sid, {
  3. AuthenticationData? auth,
})
inherited

This API endpoint uses the User-Interactive Authentication API.

Adds contact information to the user's account. Nodes should use 3PIDs added through this endpoint for password resets instead of relying on the identity server.

Nodes should prevent the caller from adding a 3PID to their account if it has already been added to another user's account on the node.

auth Additional authentication information for the user-interactive authentication API.

clientSecret The client secret used in the session with the node.

sid The session identifier given by the node.

Implementation

Future<void> add3PID(String clientSecret, String sid,
    {AuthenticationData? auth}) async {
  final requestUri = Uri(path: '_api/client/v3/account/3pid/add');
  final request = Request('POST', baseUri!.resolveUri(requestUri));
  request.headers['authorization'] = 'Bearer ${bearerToken!}';
  request.headers['content-type'] = 'application/json';
  request.bodyBytes = utf8.encode(jsonEncode({
    if (auth != null) 'auth': auth.toJson(),
    'client_secret': clientSecret,
    '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);
}