uiaLogin method

Future<LoginResponse> uiaLogin(
  1. LoginType type, {
  2. String? address,
  3. String? deviceId,
  4. AuthenticationIdentifier? identifier,
  5. String? initialDeviceDisplayName,
  6. String? medium,
  7. String? password,
  8. String? token,
  9. String? user,
  10. AuthenticationData? auth,
  11. String pathVersion = 'v3',
})

Implementation of MSC2835: https://github.com/Sorunome/sdn-doc/blob/soru/uia-on-login/proposals/2835-uia-on-login.md Set pathVersion to r0 if you need to use the previous version of the login endpoint.

Implementation

Future<LoginResponse> uiaLogin(
  LoginType type, {
  String? address,
  String? deviceId,
  AuthenticationIdentifier? identifier,
  String? initialDeviceDisplayName,
  String? medium,
  String? password,
  String? token,
  String? user,
  AuthenticationData? auth,
  String pathVersion = 'v3',
}) async {
  final requestUri = Uri(path: '_api/client/$pathVersion/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);
}