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:
|
||||
/// https://matrix.org/docs/spec/client_server/r0.6.1#phone-number-msisdn-based-identity-homeserver
|
||||
class AuthenticationThreePidCreds extends AuthenticationData {
|
||||
late List<ThreepidCreds> threepidCreds;
|
||||
late ThreepidCreds threepidCreds;
|
||||
|
||||
AuthenticationThreePidCreds(
|
||||
{String? session, required String type, required this.threepidCreds})
|
||||
|
|
@ -39,27 +39,16 @@ class AuthenticationThreePidCreds extends AuthenticationData {
|
|||
|
||||
AuthenticationThreePidCreds.fromJson(Map<String, dynamic> json)
|
||||
: super.fromJson(json) {
|
||||
if (json['threepidCreds'] != null) {
|
||||
threepidCreds = (json['threepidCreds'] as List)
|
||||
.map((item) => ThreepidCreds.fromJson(item))
|
||||
.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();
|
||||
final creds = json['threepid_creds'];
|
||||
if (creds is Map<String, dynamic>) {
|
||||
threepidCreds = ThreepidCreds.fromJson(creds);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
final data = super.toJson();
|
||||
data['threepidCreds'] = threepidCreds.map((t) => t.toJson()).toList();
|
||||
// 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();
|
||||
data['threepid_creds'] = threepidCreds.toJson();
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1807,22 +1807,12 @@ void main() {
|
|||
test('AuthenticationThreePidCreds', () {
|
||||
final json = {
|
||||
'type': 'm.login.email.identity',
|
||||
'threepidCreds': [
|
||||
{
|
||||
'threepid_creds': {
|
||||
'sid': '1',
|
||||
'client_secret': 'a',
|
||||
'id_server': 'matrix.org',
|
||||
'id_access_token': 'a',
|
||||
},
|
||||
],
|
||||
'threepid_creds': [
|
||||
{
|
||||
'sid': '1',
|
||||
'client_secret': 'a',
|
||||
'id_server': 'matrix.org',
|
||||
'id_access_token': 'a',
|
||||
},
|
||||
],
|
||||
'session': '1',
|
||||
};
|
||||
expect(AuthenticationThreePidCreds.fromJson(json).toJson(), json);
|
||||
|
|
@ -1830,14 +1820,13 @@ void main() {
|
|||
AuthenticationThreePidCreds(
|
||||
session: '1',
|
||||
type: AuthenticationTypes.emailIdentity,
|
||||
threepidCreds: [
|
||||
ThreepidCreds(
|
||||
threepidCreds: ThreepidCreds(
|
||||
sid: '1',
|
||||
clientSecret: 'a',
|
||||
idServer: 'matrix.org',
|
||||
idAccessToken: 'a',
|
||||
),
|
||||
]).toJson(),
|
||||
).toJson(),
|
||||
json);
|
||||
});
|
||||
test('AuthenticationIdentifier', () {
|
||||
|
|
|
|||
Loading…
Reference in New Issue