refactor: login method AuthenticationIdentifier
This is a breaking change for the login method to use the correct format. It makes it possible to login with email or phone. Also this does some housekeeping stuff while upgrading to pedantic 1.11.0 which doesnt allow curly braces in Strings where not needed anymore.
This commit is contained in:
parent
7d91cdac5e
commit
e28b0fa1b3
10
CHANGELOG.md
10
CHANGELOG.md
|
|
@ -1,3 +1,13 @@
|
|||
## 0.2.0
|
||||
- refactor: login method AuthenticationIdentifier
|
||||
|
||||
This is a breaking change for the login method to use the correct format.
|
||||
It makes it possible to login with email or phone.
|
||||
Also this does some housekeeping stuff while
|
||||
upgrading to pedantic 1.11.0 which doesnt
|
||||
allow curly braces in Strings where not needed
|
||||
anymore.
|
||||
|
||||
## 0.1.9
|
||||
- feat: Add support for fallback keys
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import 'dart:typed_data';
|
|||
import 'package:http/http.dart' as http;
|
||||
import 'package:mime/mime.dart';
|
||||
|
||||
import '../matrix_api_lite.dart';
|
||||
import 'model/auth/authentication_data.dart';
|
||||
import 'model/auth/authentication_types.dart';
|
||||
import 'model/device.dart';
|
||||
|
|
@ -152,7 +153,7 @@ class MatrixApi {
|
|||
?.where((x) => x.value != null)
|
||||
?.map((x) => [x.key, x.value].map(Uri.encodeQueryComponent).join('='))
|
||||
?.join('&');
|
||||
final url = ['${homeserver.toString()}/_matrix${action}', queryPart]
|
||||
final url = ['${homeserver.toString()}/_matrix$action', queryPart]
|
||||
.where((x) => x != null && x != '')
|
||||
.join('?');
|
||||
|
||||
|
|
@ -161,7 +162,7 @@ class MatrixApi {
|
|||
headers['Content-Type'] = contentType;
|
||||
}
|
||||
if (accessToken != null) {
|
||||
headers['Authorization'] = 'Bearer ${accessToken}';
|
||||
headers['Authorization'] = 'Bearer $accessToken';
|
||||
}
|
||||
|
||||
http.Response resp;
|
||||
|
|
@ -253,25 +254,25 @@ class MatrixApi {
|
|||
|
||||
/// Authenticates the user, and issues an access token they can use to authorize themself in subsequent requests.
|
||||
/// https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-login
|
||||
/// To just login with the username 'alice' you set [identifier] to:
|
||||
/// `AuthenticationUserIdentifier(user: 'alice')`
|
||||
/// Maybe you want to set [user] to the same String to stay compatible with
|
||||
/// older server versions.
|
||||
Future<LoginResponse> login({
|
||||
String type = AuthenticationTypes.password,
|
||||
String userIdentifierType,
|
||||
String user,
|
||||
String medium,
|
||||
String address,
|
||||
AuthenticationIdentifier identifier,
|
||||
String password,
|
||||
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,
|
||||
}) async {
|
||||
final response = await request(RequestType.POST, '/client/r0/login', data: {
|
||||
'type': type,
|
||||
if (userIdentifierType != null)
|
||||
'identifier': {
|
||||
'type': userIdentifierType,
|
||||
if (user != null) 'user': user,
|
||||
},
|
||||
if (identifier != null) 'identifier': identifier.toJson(),
|
||||
if (user != null) 'user': user,
|
||||
if (medium != null) 'medium': medium,
|
||||
if (address != null) 'address': address,
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
name: matrix_api_lite
|
||||
description: Dead simple data model for the matrix.org client-server API.
|
||||
version: 0.1.9
|
||||
version: 0.2.0
|
||||
homepage: https://famedly.com
|
||||
|
||||
environment:
|
||||
sdk: '>=2.10.0 <3.0.0'
|
||||
sdk: ">=2.10.0 <3.0.0"
|
||||
|
||||
dependencies:
|
||||
http: ^0.12.2
|
||||
|
|
@ -12,5 +12,5 @@ dependencies:
|
|||
mime: ^0.9.7
|
||||
|
||||
dev_dependencies:
|
||||
pedantic: ^1.9.0
|
||||
pedantic: ^1.11.0
|
||||
test: ^1.14.4
|
||||
|
|
|
|||
|
|
@ -155,8 +155,9 @@ void main() {
|
|||
});
|
||||
test('login', () async {
|
||||
matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
|
||||
final loginResponse =
|
||||
await matrixApi.login(userIdentifierType: 'username');
|
||||
final loginResponse = await matrixApi.login(
|
||||
identifier: AuthenticationUserIdentifier(user: 'username'),
|
||||
);
|
||||
expect(FakeMatrixApi.api['POST']['/client/r0/login']({}),
|
||||
loginResponse.toJson());
|
||||
matrixApi.homeserver = null;
|
||||
|
|
|
|||
Loading…
Reference in New Issue