LCOV - code coverage report
Current view: top level - lib/msc_extensions/msc_2835_uia_login - msc_2835_uia_login.dart (source / functions) Coverage Total Hit
Test: merged.info Lines: 0.0 % 23 0
Test Date: 2025-03-17 05:40:22 Functions: - 0 0

            Line data    Source code
       1              : /// Experimental login method using User Interactive Authentication
       2              : library;
       3              : 
       4              : import 'dart:convert';
       5              : 
       6              : import 'package:http/http.dart' hide Client;
       7              : 
       8              : import 'package:matrix/matrix.dart';
       9              : 
      10              : extension UiaLogin on Client {
      11              :   /// Implementation of MSC2835:
      12              :   /// https://github.com/Sorunome/matrix-doc/blob/soru/uia-on-login/proposals/2835-uia-on-login.md
      13              :   /// Set `pathVersion` to `r0` if you need to use the previous
      14              :   /// version of the login endpoint.
      15            0 :   Future<LoginResponse> uiaLogin(
      16              :     String type, {
      17              :     String? address,
      18              :     String? deviceId,
      19              :     AuthenticationIdentifier? identifier,
      20              :     String? initialDeviceDisplayName,
      21              :     String? medium,
      22              :     String? password,
      23              :     String? token,
      24              :     String? user,
      25              :     AuthenticationData? auth,
      26              :     String pathVersion = 'v3',
      27              :     bool? refreshToken,
      28              :   }) async {
      29            0 :     final requestUri = Uri(path: '_matrix/client/$pathVersion/login');
      30            0 :     final request = Request('POST', baseUri!.resolveUri(requestUri));
      31            0 :     request.headers['content-type'] = 'application/json';
      32            0 :     request.bodyBytes = utf8.encode(
      33            0 :       jsonEncode({
      34            0 :         if (address != null) 'address': address,
      35            0 :         if (deviceId != null) 'device_id': deviceId,
      36            0 :         if (identifier != null) 'identifier': identifier.toJson(),
      37              :         if (initialDeviceDisplayName != null)
      38            0 :           'initial_device_display_name': initialDeviceDisplayName,
      39            0 :         if (medium != null) 'medium': medium,
      40            0 :         if (password != null) 'password': password,
      41            0 :         if (token != null) 'token': token,
      42            0 :         'type': type,
      43            0 :         if (user != null) 'user': user,
      44            0 :         if (auth != null) 'auth': auth.toJson(),
      45            0 :         if (refreshToken != null) 'refresh_token': refreshToken,
      46              :       }),
      47              :     );
      48            0 :     final response = await httpClient.send(request);
      49            0 :     final responseBody = await response.stream.toBytes();
      50            0 :     if (response.statusCode != 200) unexpectedResponse(response, responseBody);
      51            0 :     final responseString = utf8.decode(responseBody);
      52            0 :     final json = jsonDecode(responseString);
      53            0 :     return LoginResponse.fromJson(json);
      54              :   }
      55              : }
        

Generated by: LCOV version 2.0-1