diff --git a/CHANGELOG.md b/CHANGELOG.md index 317083eb..54923ab4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ -## [0.9.0] - 4th Mai 2022 +## [0.9.1] - 9th May 2022 +- feat: Store timestamp in the presence events +- chore: Move auth object passing to external msc implementations + +## [0.9.0] - 4th May 2022 - refactor: Get rid of dynamic input in checkHomeserver (Christian Pauly) - feat: Make image size editable (Henri Carnot) diff --git a/lib/msc_extensions/msc_2835_uia_login/msc_2835_uia_login.dart b/lib/msc_extensions/msc_2835_uia_login/msc_2835_uia_login.dart new file mode 100644 index 00000000..b036ab2d --- /dev/null +++ b/lib/msc_extensions/msc_2835_uia_login/msc_2835_uia_login.dart @@ -0,0 +1,49 @@ +library msc_2835_uia_login; + +import 'dart:convert'; + +import 'package:http/http.dart' hide Client; +import 'package:matrix/matrix.dart'; + +extension UiaLogin on Client { + /// Implementation of MSC2835: + /// https://github.com/Sorunome/matrix-doc/blob/soru/uia-on-login/proposals/2835-uia-on-login.md + Future uiaLogin( + LoginType type, { + String? address, + String? deviceId, + AuthenticationIdentifier? identifier, + String? initialDeviceDisplayName, + String? medium, + String? password, + String? token, + String? user, + AuthenticationData? auth, + }) async { + final requestUri = Uri(path: '_matrix/client/v3/login'); + final request = Request('POST', baseUri!.resolveUri(requestUri)); + request.headers['content-type'] = 'application/json'; + request.bodyBytes = utf8.encode(jsonEncode({ + if (address != null) 'address': address, + if (deviceId != null) 'device_id': deviceId, + if (identifier != null) 'identifier': identifier.toJson(), + if (initialDeviceDisplayName != null) + 'initial_device_display_name': initialDeviceDisplayName, + if (medium != null) 'medium': medium, + if (password != null) 'password': password, + if (token != null) 'token': token, + 'type': { + LoginType.mLoginPassword: 'm.login.password', + LoginType.mLoginToken: 'm.login.token' + }[type]!, + if (user != null) 'user': user, + 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 LoginResponse.fromJson(json); + } +} diff --git a/lib/src/client.dart b/lib/src/client.dart index 9c6f21df..9bbfa9c3 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -451,7 +451,6 @@ class Client extends MatrixApi { String? token, String? deviceId, String? initialDeviceDisplayName, - AuthenticationData? auth, @Deprecated('Deprecated in favour of identifier.') String? user, @Deprecated('Deprecated in favour of identifier.') String? medium, @Deprecated('Deprecated in favour of identifier.') String? address, diff --git a/pubspec.yaml b/pubspec.yaml index b9079200..41e855d7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: matrix description: Matrix Dart SDK -version: 0.9.0 +version: 0.9.1 homepage: https://famedly.com repository: https://gitlab.com/famedly/company/frontend/famedlysdk.git