From c9ca93e494107c07726dd2e93ac94025a8b9e908 Mon Sep 17 00:00:00 2001 From: Illya Tsai Date: Mon, 24 Jun 2024 13:26:15 +0300 Subject: [PATCH 1/4] add refreshToken --- .../lib/src/data/mappers/deriv_passkeys_mapper.dart | 1 + ..._passkeys_verify_credentials_response_entity.dart | 6 +++++- .../states/bloc/deriv_passkeys_bloc.dart | 2 ++ .../states/bloc/deriv_passkeys_state.dart | 12 +++++++++--- .../data/deriv_passkeys_data_source_mock_setup.dart | 3 ++- .../test/data/deriv_passkeys_mapper_test.dart | 3 ++- .../states/bloc/deriv_passkeys_bloc_setup.dart | 5 ++++- .../states/bloc/deriv_passkeys_state_test.dart | 7 +++++-- 8 files changed, 30 insertions(+), 9 deletions(-) diff --git a/packages/deriv_passkeys/lib/src/data/mappers/deriv_passkeys_mapper.dart b/packages/deriv_passkeys/lib/src/data/mappers/deriv_passkeys_mapper.dart index 9404c3987..468a647cf 100644 --- a/packages/deriv_passkeys/lib/src/data/mappers/deriv_passkeys_mapper.dart +++ b/packages/deriv_passkeys/lib/src/data/mappers/deriv_passkeys_mapper.dart @@ -51,6 +51,7 @@ class DerivPasskeysMapper { DerivPasskeysVerifyCredentialsResponseModel model) => DerivPasskeysVerifyCredentialsResponseEntity( token: (model.response['tokens'] as List).first['token'], + refreshToken: model.response['refresh_token'] as String, ); /// Maps [ConnectionInfoEntity] to [PasskeysConnectionInfoModel]. diff --git a/packages/deriv_passkeys/lib/src/domain/entities/deriv_passkeys_verify_credentials_response_entity.dart b/packages/deriv_passkeys/lib/src/domain/entities/deriv_passkeys_verify_credentials_response_entity.dart index 1e249d40a..2e211a55b 100644 --- a/packages/deriv_passkeys/lib/src/domain/entities/deriv_passkeys_verify_credentials_response_entity.dart +++ b/packages/deriv_passkeys/lib/src/domain/entities/deriv_passkeys_verify_credentials_response_entity.dart @@ -5,11 +5,15 @@ final class DerivPasskeysVerifyCredentialsResponseEntity extends Equatable { /// Creates a [DerivPasskeysVerifyCredentialsResponseEntity]. const DerivPasskeysVerifyCredentialsResponseEntity({ required this.token, + required this.refreshToken, }); /// contains the token from the REST API to verify credentials. final String token; + /// contains the refresh token from the REST API to verify credentials. + final String refreshToken; + @override - List get props => [token]; + List get props => [token, refreshToken]; } diff --git a/packages/deriv_passkeys/lib/src/presentation/states/bloc/deriv_passkeys_bloc.dart b/packages/deriv_passkeys/lib/src/presentation/states/bloc/deriv_passkeys_bloc.dart index ea167db91..1a8285e7f 100644 --- a/packages/deriv_passkeys/lib/src/presentation/states/bloc/deriv_passkeys_bloc.dart +++ b/packages/deriv_passkeys/lib/src/presentation/states/bloc/deriv_passkeys_bloc.dart @@ -57,6 +57,8 @@ class DerivPasskeysBloc extends Bloc { emit( DerivPasskeysCredentialVerifiedState( token: derivPasskeysVerifyCredentialsResponseEntity.token, + refreshToken: + derivPasskeysVerifyCredentialsResponseEntity.refreshToken, ), ); }).catchError((Object error) { diff --git a/packages/deriv_passkeys/lib/src/presentation/states/bloc/deriv_passkeys_state.dart b/packages/deriv_passkeys/lib/src/presentation/states/bloc/deriv_passkeys_state.dart index e50ae555c..72f3c115e 100644 --- a/packages/deriv_passkeys/lib/src/presentation/states/bloc/deriv_passkeys_state.dart +++ b/packages/deriv_passkeys/lib/src/presentation/states/bloc/deriv_passkeys_state.dart @@ -33,13 +33,19 @@ class DerivPasskeysCreatedSuccessfullyState extends DerivPasskeysState {} /// [DerivPasskeysCredentialVerifiedState] represents the credential verified state within the DerivPasskeys flow. class DerivPasskeysCredentialVerifiedState extends DerivPasskeysState { /// Creates a [DerivPasskeysCredentialVerifiedState]. - const DerivPasskeysCredentialVerifiedState({required this.token}); + const DerivPasskeysCredentialVerifiedState({ + required this.token, + required this.refreshToken, + }); - /// The response. + /// App token from the response. final String token; + /// Refresh token from the response. + final String refreshToken; + @override - List get props => [token]; + List get props => [token, refreshToken]; } /// [DerivPasskeysNotSupportedState] represents the not supported state within the DerivPasskeys flow. diff --git a/packages/deriv_passkeys/test/data/deriv_passkeys_data_source_mock_setup.dart b/packages/deriv_passkeys/test/data/deriv_passkeys_data_source_mock_setup.dart index 221657dae..4fa40b0d0 100644 --- a/packages/deriv_passkeys/test/data/deriv_passkeys_data_source_mock_setup.dart +++ b/packages/deriv_passkeys/test/data/deriv_passkeys_data_source_mock_setup.dart @@ -99,7 +99,8 @@ const DerivPasskeysVerifyCredentialsResponseModel { 'token': 'token', }, - ] + ], + 'refresh_token': 'refresh_token', }, ); diff --git a/packages/deriv_passkeys/test/data/deriv_passkeys_mapper_test.dart b/packages/deriv_passkeys/test/data/deriv_passkeys_mapper_test.dart index 76968b9ea..8d3684c2b 100644 --- a/packages/deriv_passkeys/test/data/deriv_passkeys_mapper_test.dart +++ b/packages/deriv_passkeys/test/data/deriv_passkeys_mapper_test.dart @@ -106,7 +106,8 @@ void main() { { 'token': '', } - ] + ], + 'refresh_token': 'refresh_token', }, ); diff --git a/packages/deriv_passkeys/test/presentation/states/bloc/deriv_passkeys_bloc_setup.dart b/packages/deriv_passkeys/test/presentation/states/bloc/deriv_passkeys_bloc_setup.dart index 0c8e906c7..b293053b5 100644 --- a/packages/deriv_passkeys/test/presentation/states/bloc/deriv_passkeys_bloc_setup.dart +++ b/packages/deriv_passkeys/test/presentation/states/bloc/deriv_passkeys_bloc_setup.dart @@ -31,7 +31,10 @@ void setupDerivPasskeysBloc() { void setupSuccessDerivPasskeysVerifyCredentialEvent() { const DerivPasskeysVerifyCredentialsResponseEntity mockResponseEntity = - DerivPasskeysVerifyCredentialsResponseEntity(token: 'token'); + DerivPasskeysVerifyCredentialsResponseEntity( + token: 'token', + refreshToken: 'refresh_token', + ); when(() => mockDerivPasskeysService.verifyCredential( jwtToken: any(named: 'jwtToken'), diff --git a/packages/deriv_passkeys/test/presentation/states/bloc/deriv_passkeys_state_test.dart b/packages/deriv_passkeys/test/presentation/states/bloc/deriv_passkeys_state_test.dart index cba709665..785c6a623 100644 --- a/packages/deriv_passkeys/test/presentation/states/bloc/deriv_passkeys_state_test.dart +++ b/packages/deriv_passkeys/test/presentation/states/bloc/deriv_passkeys_state_test.dart @@ -34,8 +34,11 @@ void main() { group('DerivPasskeysCredentialVerifiedState', () { test('props should contain token', () { const String token = 'example_token'; - const DerivPasskeysState state = - DerivPasskeysCredentialVerifiedState(token: token); + const String refreshToken = 'example_refresh_token'; + const DerivPasskeysState state = DerivPasskeysCredentialVerifiedState( + token: token, + refreshToken: refreshToken, + ); expect(state.props, contains(token)); }); }); From 62ce4453b310ba88120307ec87f66be2d0c95375 Mon Sep 17 00:00:00 2001 From: Illya Tsai Date: Wed, 26 Jun 2024 15:20:38 +0300 Subject: [PATCH 2/4] fix comments --- .../deriv_passkeys_verify_credentials_response_entity.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/deriv_passkeys/lib/src/domain/entities/deriv_passkeys_verify_credentials_response_entity.dart b/packages/deriv_passkeys/lib/src/domain/entities/deriv_passkeys_verify_credentials_response_entity.dart index 2e211a55b..aeeca7d38 100644 --- a/packages/deriv_passkeys/lib/src/domain/entities/deriv_passkeys_verify_credentials_response_entity.dart +++ b/packages/deriv_passkeys/lib/src/domain/entities/deriv_passkeys_verify_credentials_response_entity.dart @@ -8,10 +8,10 @@ final class DerivPasskeysVerifyCredentialsResponseEntity extends Equatable { required this.refreshToken, }); - /// contains the token from the REST API to verify credentials. + /// App token from the REST API to verify credentials. final String token; - /// contains the refresh token from the REST API to verify credentials. + /// Refresh token from the REST API to verify credentials. final String refreshToken; @override From 3ddea682bdd84046c1119d31b4183273a87b0851 Mon Sep 17 00:00:00 2001 From: Illya Tsai Date: Thu, 27 Jun 2024 09:10:10 +0300 Subject: [PATCH 3/4] update version --- packages/deriv_passkeys/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/deriv_passkeys/pubspec.yaml b/packages/deriv_passkeys/pubspec.yaml index f51b9c42d..9bcfbf2f1 100644 --- a/packages/deriv_passkeys/pubspec.yaml +++ b/packages/deriv_passkeys/pubspec.yaml @@ -1,6 +1,6 @@ name: deriv_passkeys description: Deriv Passkeys Flutter Plugin -version: 0.0.2 +version: 0.0.2+6 publish_to: "none" environment: From f640a948eb58118780932a04928c3ccb29fd6ec0 Mon Sep 17 00:00:00 2001 From: Illya Tsai Date: Thu, 27 Jun 2024 14:06:37 +0300 Subject: [PATCH 4/4] update auth package --- .../lib/features/auth/cubit/deriv_auth_cubit.dart | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/deriv_auth/lib/features/auth/cubit/deriv_auth_cubit.dart b/packages/deriv_auth/lib/features/auth/cubit/deriv_auth_cubit.dart index 53eb7fb2a..3f47e5ab1 100644 --- a/packages/deriv_auth/lib/features/auth/cubit/deriv_auth_cubit.dart +++ b/packages/deriv_auth/lib/features/auth/cubit/deriv_auth_cubit.dart @@ -103,11 +103,15 @@ class DerivAuthCubit extends Cubit } @override - Future tokenLogin(String token) async { + Future tokenLogin( + String token, [ + String? refreshToken, + ]) async { emit(DerivAuthLoadingState()); await _tokenLoginRequest( token, + refreshToken: refreshToken, accounts: await authService.getLatestAccounts(), ); } @@ -145,11 +149,15 @@ class DerivAuthCubit extends Cubit Future _tokenLoginRequest( String token, { + String? refreshToken, required List accounts, }) async { try { - final AuthorizeEntity authorizeEntity = - await authService.login(token, accounts: accounts); + final AuthorizeEntity authorizeEntity = await authService.login( + token, + refreshToken: refreshToken, + accounts: accounts, + ); final LandingCompanyEntity landingCompanyEntity = await authService.getLandingCompany(authorizeEntity.country); _isUserMigrated = _checkUserMigrated(authorizeEntity);