From 05e1a4aab1204163a57d8948d85b42aaabb683a9 Mon Sep 17 00:00:00 2001 From: Henry-Hiles Date: Mon, 21 Jul 2025 21:43:04 -0400 Subject: [PATCH] Add nonce support --- lib/helpers/api_helper.dart | 10 +++++++- lib/models/matrix_user.dart | 1 + lib/models/matrix_user.freezed.dart | 37 ++++++++++++++++------------- lib/models/matrix_user.g.dart | 12 ++++++---- 4 files changed, 37 insertions(+), 23 deletions(-) diff --git a/lib/helpers/api_helper.dart b/lib/helpers/api_helper.dart index d0c5ce3..c3fa10e 100644 --- a/lib/helpers/api_helper.dart +++ b/lib/helpers/api_helper.dart @@ -41,7 +41,14 @@ class ApiHelper { ref .read(AuthCodeController.provider.notifier) - .set(code, MatrixUser(userId: userId, matrixToken: accessToken)); + .set( + code, + MatrixUser( + userId: userId, + matrixToken: accessToken, + nonce: data["nonce"], + ), + ); final uri = Uri.parse(redirectUri); @@ -108,6 +115,7 @@ class ApiHelper { 1000, "email": "$name@federated.nexus", "name": name, + "nonce": user.nonce, "iat": DateTime.now().millisecondsSinceEpoch ~/ 1000, }, subject: user.userId, diff --git a/lib/models/matrix_user.dart b/lib/models/matrix_user.dart index 805fb3f..d763865 100644 --- a/lib/models/matrix_user.dart +++ b/lib/models/matrix_user.dart @@ -8,6 +8,7 @@ abstract class MatrixUser with _$MatrixUser { const factory MatrixUser({ required String userId, required String matrixToken, + required String? nonce, }) = _MatrixUser; factory MatrixUser.fromJson(Map json) => diff --git a/lib/models/matrix_user.freezed.dart b/lib/models/matrix_user.freezed.dart index 94504e8..e9eaf24 100644 --- a/lib/models/matrix_user.freezed.dart +++ b/lib/models/matrix_user.freezed.dart @@ -4,7 +4,7 @@ // ignore_for_file: type=lint // ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark -part of "matrix_user.dart"; +part of 'matrix_user.dart'; // ************************************************************************** // FreezedGenerator @@ -16,11 +16,11 @@ T _$identity(T value) => value; /// @nodoc mixin _$MatrixUser { - String get userId; String get matrixToken; + String get userId; String get matrixToken; String? get nonce; /// Create a copy of MatrixUser /// with the given fields replaced by the non-null parameter values. @JsonKey(includeFromJson: false, includeToJson: false) -@pragma("vm:prefer-inline") +@pragma('vm:prefer-inline') $MatrixUserCopyWith get copyWith => _$MatrixUserCopyWithImpl(this as MatrixUser, _$identity); /// Serializes this MatrixUser to a JSON map. @@ -29,16 +29,16 @@ $MatrixUserCopyWith get copyWith => _$MatrixUserCopyWithImpl Object.hash(runtimeType,userId,matrixToken); +int get hashCode => Object.hash(runtimeType,userId,matrixToken,nonce); @override String toString() { - return "MatrixUser(userId: $userId, matrixToken: $matrixToken)"; + return 'MatrixUser(userId: $userId, matrixToken: $matrixToken, nonce: $nonce)'; } @@ -49,7 +49,7 @@ abstract mixin class $MatrixUserCopyWith<$Res> { factory $MatrixUserCopyWith(MatrixUser value, $Res Function(MatrixUser) _then) = _$MatrixUserCopyWithImpl; @useResult $Res call({ - String userId, String matrixToken + String userId, String matrixToken, String? nonce }); @@ -66,11 +66,12 @@ class _$MatrixUserCopyWithImpl<$Res> /// Create a copy of MatrixUser /// with the given fields replaced by the non-null parameter values. -@pragma("vm:prefer-inline") @override $Res call({Object? userId = null,Object? matrixToken = null,}) { +@pragma('vm:prefer-inline') @override $Res call({Object? userId = null,Object? matrixToken = null,Object? nonce = freezed,}) { return _then(_self.copyWith( userId: null == userId ? _self.userId : userId // ignore: cast_nullable_to_non_nullable as String,matrixToken: null == matrixToken ? _self.matrixToken : matrixToken // ignore: cast_nullable_to_non_nullable -as String, +as String,nonce: freezed == nonce ? _self.nonce : nonce // ignore: cast_nullable_to_non_nullable +as String?, )); } @@ -81,16 +82,17 @@ as String, @JsonSerializable() class _MatrixUser implements MatrixUser { - const _MatrixUser({required this.userId, required this.matrixToken}); + const _MatrixUser({required this.userId, required this.matrixToken, required this.nonce}); factory _MatrixUser.fromJson(Map json) => _$MatrixUserFromJson(json); @override final String userId; @override final String matrixToken; +@override final String? nonce; /// Create a copy of MatrixUser /// with the given fields replaced by the non-null parameter values. @override @JsonKey(includeFromJson: false, includeToJson: false) -@pragma("vm:prefer-inline") +@pragma('vm:prefer-inline') _$MatrixUserCopyWith<_MatrixUser> get copyWith => __$MatrixUserCopyWithImpl<_MatrixUser>(this, _$identity); @override @@ -100,16 +102,16 @@ Map toJson() { @override bool operator ==(Object other) { - return identical(this, other) || (other.runtimeType == runtimeType&&other is _MatrixUser&&(identical(other.userId, userId) || other.userId == userId)&&(identical(other.matrixToken, matrixToken) || other.matrixToken == matrixToken)); + return identical(this, other) || (other.runtimeType == runtimeType&&other is _MatrixUser&&(identical(other.userId, userId) || other.userId == userId)&&(identical(other.matrixToken, matrixToken) || other.matrixToken == matrixToken)&&(identical(other.nonce, nonce) || other.nonce == nonce)); } @JsonKey(includeFromJson: false, includeToJson: false) @override -int get hashCode => Object.hash(runtimeType,userId,matrixToken); +int get hashCode => Object.hash(runtimeType,userId,matrixToken,nonce); @override String toString() { - return "MatrixUser(userId: $userId, matrixToken: $matrixToken)"; + return 'MatrixUser(userId: $userId, matrixToken: $matrixToken, nonce: $nonce)'; } @@ -120,7 +122,7 @@ abstract mixin class _$MatrixUserCopyWith<$Res> implements $MatrixUserCopyWith<$ factory _$MatrixUserCopyWith(_MatrixUser value, $Res Function(_MatrixUser) _then) = __$MatrixUserCopyWithImpl; @override @useResult $Res call({ - String userId, String matrixToken + String userId, String matrixToken, String? nonce }); @@ -137,11 +139,12 @@ class __$MatrixUserCopyWithImpl<$Res> /// Create a copy of MatrixUser /// with the given fields replaced by the non-null parameter values. -@override @pragma("vm:prefer-inline") $Res call({Object? userId = null,Object? matrixToken = null,}) { +@override @pragma('vm:prefer-inline') $Res call({Object? userId = null,Object? matrixToken = null,Object? nonce = freezed,}) { return _then(_MatrixUser( userId: null == userId ? _self.userId : userId // ignore: cast_nullable_to_non_nullable as String,matrixToken: null == matrixToken ? _self.matrixToken : matrixToken // ignore: cast_nullable_to_non_nullable -as String, +as String,nonce: freezed == nonce ? _self.nonce : nonce // ignore: cast_nullable_to_non_nullable +as String?, )); } diff --git a/lib/models/matrix_user.g.dart b/lib/models/matrix_user.g.dart index 95e855f..d9f38c8 100644 --- a/lib/models/matrix_user.g.dart +++ b/lib/models/matrix_user.g.dart @@ -1,18 +1,20 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -part of "matrix_user.dart"; +part of 'matrix_user.dart'; // ************************************************************************** // JsonSerializableGenerator // ************************************************************************** _MatrixUser _$MatrixUserFromJson(Map json) => _MatrixUser( - userId: json["userId"] as String, - matrixToken: json["matrixToken"] as String, + userId: json['userId'] as String, + matrixToken: json['matrixToken'] as String, + nonce: json['nonce'] as String?, ); Map _$MatrixUserToJson(_MatrixUser instance) => { - "userId": instance.userId, - "matrixToken": instance.matrixToken, + 'userId': instance.userId, + 'matrixToken': instance.matrixToken, + 'nonce': instance.nonce, };