fix: threepidCreds should be threepid_creds and an object
For context, see https://github.com/matrix-org/matrix-doc/pull/3471 Basically the spec was wrong and didn't match what clients and servers were doing. Might fix registration on matrix.org. BREAKING CHANGE: Any client that implements the email portion will fail to build now.
This commit is contained in:
parent
7a4bb507fe
commit
3e7a6df81b
|
|
@ -28,7 +28,7 @@ import 'authentication_data.dart';
|
||||||
/// Or phone number based identity:
|
/// Or phone number based identity:
|
||||||
/// https://matrix.org/docs/spec/client_server/r0.6.1#phone-number-msisdn-based-identity-homeserver
|
/// https://matrix.org/docs/spec/client_server/r0.6.1#phone-number-msisdn-based-identity-homeserver
|
||||||
class AuthenticationThreePidCreds extends AuthenticationData {
|
class AuthenticationThreePidCreds extends AuthenticationData {
|
||||||
late List<ThreepidCreds> threepidCreds;
|
late ThreepidCreds threepidCreds;
|
||||||
|
|
||||||
AuthenticationThreePidCreds(
|
AuthenticationThreePidCreds(
|
||||||
{String? session, required String type, required this.threepidCreds})
|
{String? session, required String type, required this.threepidCreds})
|
||||||
|
|
@ -39,27 +39,16 @@ class AuthenticationThreePidCreds extends AuthenticationData {
|
||||||
|
|
||||||
AuthenticationThreePidCreds.fromJson(Map<String, dynamic> json)
|
AuthenticationThreePidCreds.fromJson(Map<String, dynamic> json)
|
||||||
: super.fromJson(json) {
|
: super.fromJson(json) {
|
||||||
if (json['threepidCreds'] != null) {
|
final creds = json['threepid_creds'];
|
||||||
threepidCreds = (json['threepidCreds'] as List)
|
if (creds is Map<String, dynamic>) {
|
||||||
.map((item) => ThreepidCreds.fromJson(item))
|
threepidCreds = ThreepidCreds.fromJson(creds);
|
||||||
.toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is so extremly stupid... kill it with fire!
|
|
||||||
if (json['threepid_creds'] != null) {
|
|
||||||
threepidCreds = (json['threepid_creds'] as List)
|
|
||||||
.map((item) => ThreepidCreds.fromJson(item))
|
|
||||||
.toList();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Map<String, dynamic> toJson() {
|
Map<String, dynamic> toJson() {
|
||||||
final data = super.toJson();
|
final data = super.toJson();
|
||||||
data['threepidCreds'] = threepidCreds.map((t) => t.toJson()).toList();
|
data['threepid_creds'] = threepidCreds.toJson();
|
||||||
// Help me! I'm prisoned in a developer factory against my will,
|
|
||||||
// where we are forced to work with json like this!!
|
|
||||||
data['threepid_creds'] = threepidCreds.map((t) => t.toJson()).toList();
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1807,37 +1807,26 @@ void main() {
|
||||||
test('AuthenticationThreePidCreds', () {
|
test('AuthenticationThreePidCreds', () {
|
||||||
final json = {
|
final json = {
|
||||||
'type': 'm.login.email.identity',
|
'type': 'm.login.email.identity',
|
||||||
'threepidCreds': [
|
'threepid_creds': {
|
||||||
{
|
'sid': '1',
|
||||||
'sid': '1',
|
'client_secret': 'a',
|
||||||
'client_secret': 'a',
|
'id_server': 'matrix.org',
|
||||||
'id_server': 'matrix.org',
|
'id_access_token': 'a',
|
||||||
'id_access_token': 'a',
|
},
|
||||||
},
|
|
||||||
],
|
|
||||||
'threepid_creds': [
|
|
||||||
{
|
|
||||||
'sid': '1',
|
|
||||||
'client_secret': 'a',
|
|
||||||
'id_server': 'matrix.org',
|
|
||||||
'id_access_token': 'a',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
'session': '1',
|
'session': '1',
|
||||||
};
|
};
|
||||||
expect(AuthenticationThreePidCreds.fromJson(json).toJson(), json);
|
expect(AuthenticationThreePidCreds.fromJson(json).toJson(), json);
|
||||||
expect(
|
expect(
|
||||||
AuthenticationThreePidCreds(
|
AuthenticationThreePidCreds(
|
||||||
session: '1',
|
session: '1',
|
||||||
type: AuthenticationTypes.emailIdentity,
|
type: AuthenticationTypes.emailIdentity,
|
||||||
threepidCreds: [
|
threepidCreds: ThreepidCreds(
|
||||||
ThreepidCreds(
|
sid: '1',
|
||||||
sid: '1',
|
clientSecret: 'a',
|
||||||
clientSecret: 'a',
|
idServer: 'matrix.org',
|
||||||
idServer: 'matrix.org',
|
idAccessToken: 'a',
|
||||||
idAccessToken: 'a',
|
),
|
||||||
),
|
).toJson(),
|
||||||
]).toJson(),
|
|
||||||
json);
|
json);
|
||||||
});
|
});
|
||||||
test('AuthenticationIdentifier', () {
|
test('AuthenticationIdentifier', () {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue