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
|
## 0.1.9
|
||||||
- feat: Add support for fallback keys
|
- feat: Add support for fallback keys
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ import 'dart:typed_data';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
import 'package:mime/mime.dart';
|
import 'package:mime/mime.dart';
|
||||||
|
|
||||||
|
import '../matrix_api_lite.dart';
|
||||||
import 'model/auth/authentication_data.dart';
|
import 'model/auth/authentication_data.dart';
|
||||||
import 'model/auth/authentication_types.dart';
|
import 'model/auth/authentication_types.dart';
|
||||||
import 'model/device.dart';
|
import 'model/device.dart';
|
||||||
|
|
@ -152,7 +153,7 @@ class MatrixApi {
|
||||||
?.where((x) => x.value != null)
|
?.where((x) => x.value != null)
|
||||||
?.map((x) => [x.key, x.value].map(Uri.encodeQueryComponent).join('='))
|
?.map((x) => [x.key, x.value].map(Uri.encodeQueryComponent).join('='))
|
||||||
?.join('&');
|
?.join('&');
|
||||||
final url = ['${homeserver.toString()}/_matrix${action}', queryPart]
|
final url = ['${homeserver.toString()}/_matrix$action', queryPart]
|
||||||
.where((x) => x != null && x != '')
|
.where((x) => x != null && x != '')
|
||||||
.join('?');
|
.join('?');
|
||||||
|
|
||||||
|
|
@ -161,7 +162,7 @@ class MatrixApi {
|
||||||
headers['Content-Type'] = contentType;
|
headers['Content-Type'] = contentType;
|
||||||
}
|
}
|
||||||
if (accessToken != null) {
|
if (accessToken != null) {
|
||||||
headers['Authorization'] = 'Bearer ${accessToken}';
|
headers['Authorization'] = 'Bearer $accessToken';
|
||||||
}
|
}
|
||||||
|
|
||||||
http.Response resp;
|
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.
|
/// 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
|
/// 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({
|
Future<LoginResponse> login({
|
||||||
String type = AuthenticationTypes.password,
|
String type = AuthenticationTypes.password,
|
||||||
String userIdentifierType,
|
AuthenticationIdentifier identifier,
|
||||||
String user,
|
|
||||||
String medium,
|
|
||||||
String address,
|
|
||||||
String password,
|
String password,
|
||||||
String token,
|
String token,
|
||||||
String deviceId,
|
String deviceId,
|
||||||
String initialDeviceDisplayName,
|
String initialDeviceDisplayName,
|
||||||
AuthenticationData auth,
|
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 {
|
}) async {
|
||||||
final response = await request(RequestType.POST, '/client/r0/login', data: {
|
final response = await request(RequestType.POST, '/client/r0/login', data: {
|
||||||
'type': type,
|
'type': type,
|
||||||
if (userIdentifierType != null)
|
if (identifier != null) 'identifier': identifier.toJson(),
|
||||||
'identifier': {
|
|
||||||
'type': userIdentifierType,
|
|
||||||
if (user != null) 'user': user,
|
|
||||||
},
|
|
||||||
if (user != null) 'user': user,
|
if (user != null) 'user': user,
|
||||||
if (medium != null) 'medium': medium,
|
if (medium != null) 'medium': medium,
|
||||||
if (address != null) 'address': address,
|
if (address != null) 'address': address,
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
name: matrix_api_lite
|
name: matrix_api_lite
|
||||||
description: Dead simple data model for the matrix.org client-server API.
|
description: Dead simple data model for the matrix.org client-server API.
|
||||||
version: 0.1.9
|
version: 0.2.0
|
||||||
homepage: https://famedly.com
|
homepage: https://famedly.com
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=2.10.0 <3.0.0'
|
sdk: ">=2.10.0 <3.0.0"
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
http: ^0.12.2
|
http: ^0.12.2
|
||||||
|
|
@ -12,5 +12,5 @@ dependencies:
|
||||||
mime: ^0.9.7
|
mime: ^0.9.7
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
pedantic: ^1.9.0
|
pedantic: ^1.11.0
|
||||||
test: ^1.14.4
|
test: ^1.14.4
|
||||||
|
|
|
||||||
|
|
@ -155,8 +155,9 @@ void main() {
|
||||||
});
|
});
|
||||||
test('login', () async {
|
test('login', () async {
|
||||||
matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
|
matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
|
||||||
final loginResponse =
|
final loginResponse = await matrixApi.login(
|
||||||
await matrixApi.login(userIdentifierType: 'username');
|
identifier: AuthenticationUserIdentifier(user: 'username'),
|
||||||
|
);
|
||||||
expect(FakeMatrixApi.api['POST']['/client/r0/login']({}),
|
expect(FakeMatrixApi.api['POST']['/client/r0/login']({}),
|
||||||
loginResponse.toJson());
|
loginResponse.toJson());
|
||||||
matrixApi.homeserver = null;
|
matrixApi.homeserver = null;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue