deleteDevice method
This API endpoint uses the User-Interactive Authentication API, except when used by an application service.
Deletes the given device, and invalidates any access token associated with it.
WARNING: When this endpoint requires User-Interactive Authentication, it cannot be used when the access token was obtained via the OAuth 2.0 API.
WARNING:
Added in `v1.18` OAuth 2.0 aware clients
MUST NOT use this endpoint when the server supports the OAuth 2.0 API.
Instead they MUST refer the user to the account management URL,
if available, with the action=org.matrix.device_delete and device_id={deviceId} parameters.
deviceId The device to delete.
auth Additional authentication information for the
user-interactive authentication API.
Implementation
Future<void> deleteDevice(String deviceId, {AuthenticationData? auth}) async {
final requestUri = Uri(
path: '_matrix/client/v3/devices/${Uri.encodeComponent(deviceId)}',
);
final request = Request('DELETE', 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()}),
);
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);
}