From 7677bfef267883a47ad0f113bf2423ede30ec11e Mon Sep 17 00:00:00 2001 From: akhil-deriv Date: Fri, 26 Apr 2024 15:06:13 +0400 Subject: [PATCH 01/29] added tokenList --- .../features/auth/repository/base_auth_repository.dart | 5 ++++- .../lib/features/auth/services/base_auth_service.dart | 1 + .../lib/features/auth/services/deriv_auth_service.dart | 8 +++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/deriv_auth/lib/features/auth/repository/base_auth_repository.dart b/packages/deriv_auth/lib/features/auth/repository/base_auth_repository.dart index 3d5aa3e5c..5e0203ad3 100644 --- a/packages/deriv_auth/lib/features/auth/repository/base_auth_repository.dart +++ b/packages/deriv_auth/lib/features/auth/repository/base_auth_repository.dart @@ -5,7 +5,10 @@ import 'package:deriv_auth/core/models/landig_comany_model.dart'; /// Interface of all authentication functions required from client. abstract class BaseAuthRepository { /// Authorize user with [token]. - Future authorize(String? token); + Future authorize( + String? token, { + List? tokenList, + }); /// Client functionality after user logs in. Future onLogin(AuthorizeEntity authorizeEntity); diff --git a/packages/deriv_auth/lib/features/auth/services/base_auth_service.dart b/packages/deriv_auth/lib/features/auth/services/base_auth_service.dart index f3df80e13..9470f1ea2 100644 --- a/packages/deriv_auth/lib/features/auth/services/base_auth_service.dart +++ b/packages/deriv_auth/lib/features/auth/services/base_auth_service.dart @@ -15,6 +15,7 @@ abstract class BaseAuthService { Future login( String token, { required List accounts, + List? tokenList, String? signupProvider, String? refreshToken, }); diff --git a/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart b/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart index 573bb7567..a50c5c655 100644 --- a/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart +++ b/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart @@ -59,10 +59,15 @@ class DerivAuthService extends BaseAuthService { _filterSupportedAccounts(_response.accounts); final String? _defaultAccountToken = _supportedAccounts.first.token; + final List? _tokenList = _supportedAccounts + .where((AccountModel account) => account.token != null) + .map((AccountModel accountModel) => accountModel.token!) + .toList(); if (_defaultAccountToken != null) { return login( _defaultAccountToken, + tokenList: _tokenList, accounts: _supportedAccounts, signupProvider: request.signupProvider, refreshToken: _response.refreshToken, @@ -90,12 +95,13 @@ class DerivAuthService extends BaseAuthService { Future login( String token, { required List accounts, + List? tokenList, String? signupProvider, String? refreshToken, }) async { try { final AuthorizeEntity? responseAuthorizeEntity = - (await authRepository.authorize(token)).authorize; + (await authRepository.authorize(token, tokenList: tokenList)).authorize; _checkAuthorizeValidity(responseAuthorizeEntity); From 23b9613dc67ef5f8b1122ca202b80980eccf69f5 Mon Sep 17 00:00:00 2001 From: akhil-deriv Date: Fri, 26 Apr 2024 16:24:06 +0400 Subject: [PATCH 02/29] updated deriv auth service --- .../auth/services/deriv_auth_service.dart | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart b/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart index a50c5c655..9aa14a9a3 100644 --- a/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart +++ b/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart @@ -59,15 +59,19 @@ class DerivAuthService extends BaseAuthService { _filterSupportedAccounts(_response.accounts); final String? _defaultAccountToken = _supportedAccounts.first.token; - final List? _tokenList = _supportedAccounts - .where((AccountModel account) => account.token != null) - .map((AccountModel accountModel) => accountModel.token!) - .toList(); + final List _tokenList = []; + + for (int i = 0; i < _supportedAccounts.length; i++) { + print(_supportedAccounts[i].token); + if (i != 0 && _supportedAccounts[i].token != null) { + _tokenList.add(_supportedAccounts[i].token!); + } + } if (_defaultAccountToken != null) { return login( _defaultAccountToken, - tokenList: _tokenList, + tokenList: _tokenList.isEmpty ? null : _tokenList, accounts: _supportedAccounts, signupProvider: request.signupProvider, refreshToken: _response.refreshToken, @@ -101,7 +105,8 @@ class DerivAuthService extends BaseAuthService { }) async { try { final AuthorizeEntity? responseAuthorizeEntity = - (await authRepository.authorize(token, tokenList: tokenList)).authorize; + (await authRepository.authorize(token, tokenList: tokenList)) + .authorize; _checkAuthorizeValidity(responseAuthorizeEntity); From a1186368a6a0e741b7d278dedf9482df951b1ec2 Mon Sep 17 00:00:00 2001 From: akhil-deriv Date: Mon, 29 Apr 2024 11:42:13 +0400 Subject: [PATCH 03/29] added print statement check --- .../lib/features/auth/services/deriv_auth_service.dart | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart b/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart index 9aa14a9a3..728d92089 100644 --- a/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart +++ b/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart @@ -104,6 +104,10 @@ class DerivAuthService extends BaseAuthService { String? refreshToken, }) async { try { + if (tokenList?.isNotEmpty ?? false) { + print( + '------------------ RUNNING MULTI TOKEN AUTHORIZATION ------------------'); + } final AuthorizeEntity? responseAuthorizeEntity = (await authRepository.authorize(token, tokenList: tokenList)) .authorize; From 88df298e73c93915749355609f9f8a8bcbd9f7e2 Mon Sep 17 00:00:00 2001 From: akhil-deriv Date: Mon, 6 May 2024 09:11:17 +0400 Subject: [PATCH 04/29] feat: implemented multi-token authorization in Deriv Auth --- .../features/auth/cubit/deriv_auth_cubit.dart | 20 +++++++++++++++---- .../lib/features/auth/deriv_auth_io.dart | 2 +- .../auth/services/deriv_auth_service.dart | 17 +++++----------- 3 files changed, 22 insertions(+), 17 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 481787c6d..35b835f79 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 @@ -86,11 +86,12 @@ class DerivAuthCubit extends Cubit implements DerivAuthIO { } @override - Future tokenLogin(String token) async { + Future tokenLogin(String token, {List? tokenList}) async { emit(DerivAuthLoadingState()); await _tokenLoginRequest( token, + tokenList: tokenList, accounts: await authService.getLatestAccounts(), ); } @@ -126,10 +127,11 @@ class DerivAuthCubit extends Cubit implements DerivAuthIO { Future _tokenLoginRequest( String token, { required List accounts, + List? tokenList, }) async { try { - final AuthorizeEntity authorizeEntity = - await authService.login(token, accounts: accounts); + final AuthorizeEntity authorizeEntity = await authService.login(token, + accounts: accounts, tokenList: tokenList); final LandingCompanyEntity landingCompanyEntity = await authService.getLandingCompany(authorizeEntity.country); _isUserMigrated = _checkUserMigrated(authorizeEntity); @@ -152,6 +154,9 @@ class DerivAuthCubit extends Cubit implements DerivAuthIO { Future authorizeDefaultAccount() async { emit(DerivAuthLoadingState()); + List tokenList = []; + final List accountList = + await authService.getLatestAccounts(); final String? defaultAccountToken = (await authService.getDefaultAccount())?.token; @@ -159,11 +164,18 @@ class DerivAuthCubit extends Cubit implements DerivAuthIO { emit(DerivAuthLoggedOutState()); return; + } else { + tokenList = accountList + .where((AccountModel account) => + account.token != null && defaultAccountToken != account.token) + .map((AccountModel account) => account.token!) + .toList(); } await _tokenLoginRequest( defaultAccountToken, - accounts: await authService.getLatestAccounts(), + accounts: accountList, + tokenList: tokenList, ); } diff --git a/packages/deriv_auth/lib/features/auth/deriv_auth_io.dart b/packages/deriv_auth/lib/features/auth/deriv_auth_io.dart index ad5c07f1b..c72401b34 100644 --- a/packages/deriv_auth/lib/features/auth/deriv_auth_io.dart +++ b/packages/deriv_auth/lib/features/auth/deriv_auth_io.dart @@ -27,7 +27,7 @@ abstract class DerivAuthIO { }); /// Log user in with [token] after reset password or sign up. - Future tokenLogin(String token); + Future tokenLogin(String token, {List? tokenList}); /// Log user out. Future logout(); diff --git a/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart b/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart index 728d92089..8151eb59d 100644 --- a/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart +++ b/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart @@ -59,14 +59,11 @@ class DerivAuthService extends BaseAuthService { _filterSupportedAccounts(_response.accounts); final String? _defaultAccountToken = _supportedAccounts.first.token; - final List _tokenList = []; - - for (int i = 0; i < _supportedAccounts.length; i++) { - print(_supportedAccounts[i].token); - if (i != 0 && _supportedAccounts[i].token != null) { - _tokenList.add(_supportedAccounts[i].token!); - } - } + final List _tokenList = _supportedAccounts + .sublist(1) + .where((AccountModel account) => account.token != null) + .map((AccountModel account) => account.token!) + .toList(); if (_defaultAccountToken != null) { return login( @@ -104,10 +101,6 @@ class DerivAuthService extends BaseAuthService { String? refreshToken, }) async { try { - if (tokenList?.isNotEmpty ?? false) { - print( - '------------------ RUNNING MULTI TOKEN AUTHORIZATION ------------------'); - } final AuthorizeEntity? responseAuthorizeEntity = (await authRepository.authorize(token, tokenList: tokenList)) .authorize; From 622b52890cd00588769af8529227a784c0e2bebf Mon Sep 17 00:00:00 2001 From: akhil-deriv Date: Tue, 7 May 2024 11:26:40 +0400 Subject: [PATCH 05/29] fix: fixed test cases for deriv auth --- .../auth/cubit/deriv_auth_cubit_test.dart | 46 ++++++++++++------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/packages/deriv_auth/test/features/auth/cubit/deriv_auth_cubit_test.dart b/packages/deriv_auth/test/features/auth/cubit/deriv_auth_cubit_test.dart index 73829497f..e4c3d103e 100644 --- a/packages/deriv_auth/test/features/auth/cubit/deriv_auth_cubit_test.dart +++ b/packages/deriv_auth/test/features/auth/cubit/deriv_auth_cubit_test.dart @@ -1,3 +1,4 @@ +import 'dart:async'; import 'package:bloc_test/bloc_test.dart'; import 'package:deriv_auth/core/exceptions/deriv_auth_exception.dart'; import 'package:deriv_auth/core/models/account_model.dart'; @@ -32,7 +33,10 @@ void main() { expect(authCubit.output, isA>()); }); - test('should emit [AuthLoggedOutState] for the first app start.', () { + test('should emit [AuthLoggedOutState] for the first app start.', + () async { + when(() => service.getLatestAccounts()).thenAnswer( + (_) => Future>.value([])); when(() => service.getDefaultAccount()) .thenAnswer((_) => Future.value()); @@ -42,20 +46,22 @@ void main() { isA(), ]; - expectLater( + unawaited(expectLater( authCubit.stream, emitsInOrder(expectedResponse), - ); + )); - authCubit.authorizeDefaultAccount(); + await authCubit.authorizeDefaultAccount(); + verify(() => service.getLatestAccounts()).called(1); verify(() => service.getDefaultAccount()).called(1); verifyNever( () => service.login(any(), accounts: any(named: 'accounts')), ); }); - test('should emit [AuthLoggedInState] if there is default account.', () { + test('should emit [AuthLoggedInState] if there is default account.', + () async { when(() => service.getDefaultAccount()) .thenAnswer((_) => Future.value(mockedAccountModel)); @@ -66,9 +72,11 @@ void main() { when(() => service.getLandingCompany(any())).thenAnswer((_) => Future.value(const LandingCompanyEntity())); - when(() => service.login(any(), accounts: any(named: 'accounts'))) - .thenAnswer((_) => - Future.value(mockedValidAuthorizeEntity)); + when(() => service + .login(any(), + accounts: any(named: 'accounts'), + tokenList: [])).thenAnswer( + (_) => Future.value(mockedValidAuthorizeEntity)); final List> expectedResponse = >[ @@ -76,12 +84,12 @@ void main() { isA(), ]; - expectLater( + unawaited(expectLater( authCubit.stream, emitsInOrder(expectedResponse), - ); + )); - authCubit.authorizeDefaultAccount(); + await authCubit.authorizeDefaultAccount(); verify(() => service.getDefaultAccount()).called(1); }); @@ -242,9 +250,11 @@ void main() { Future>.value( [mockedAccountModel])); - when(() => service.login(any(), accounts: any(named: 'accounts'))) - .thenAnswer((_) => - Future.value(mockedValidAuthorizeEntity)); + when(() => service + .login(any(), + accounts: any(named: 'accounts'), + tokenList: [])).thenAnswer( + (_) => Future.value(mockedValidAuthorizeEntity)); final List> expectedResponse = >[ @@ -260,10 +270,11 @@ void main() { emitsInOrder(expectedResponse), ); - authCubit.tokenLogin(_token); + authCubit.tokenLogin(_token, tokenList: []); verify( - () => service.login(any(), accounts: any(named: 'accounts')), + () => service.login(any(), + accounts: any(named: 'accounts'), tokenList: []), ).called(1); }); @@ -296,7 +307,8 @@ void main() { authCubit.tokenLogin(_token); verify( - () => service.login(any(), accounts: any(named: 'accounts')), + () => service.login(any(), + accounts: any(named: 'accounts'), tokenList: []), ).called(1); }); From b3a7a395e91b8b5ec04a0513ccf8cdd64595af55 Mon Sep 17 00:00:00 2001 From: akhil-deriv Date: Thu, 30 May 2024 12:44:43 +0400 Subject: [PATCH 06/29] added tokenLogin changes --- .../lib/features/auth/cubit/deriv_auth_cubit.dart | 10 +++++++++- .../lib/features/auth/services/deriv_auth_service.dart | 8 ++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) 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 35b835f79..b34de146e 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 @@ -88,7 +88,15 @@ class DerivAuthCubit extends Cubit implements DerivAuthIO { @override Future tokenLogin(String token, {List? tokenList}) async { emit(DerivAuthLoadingState()); - + if (tokenList == null) { + final List accountList = + await authService.getLatestAccounts(); + tokenList = accountList + .where((AccountModel account) => + account.token != null && token != account.token) + .map((AccountModel account) => account.token!) + .toList(); + } await _tokenLoginRequest( token, tokenList: tokenList, diff --git a/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart b/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart index 8151eb59d..e8fa144c2 100644 --- a/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart +++ b/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart @@ -101,6 +101,14 @@ class DerivAuthService extends BaseAuthService { String? refreshToken, }) async { try { + if (tokenList != null && tokenList.isNotEmpty) { + print( + '------------------------ RUNNING MULTI TOKEN AUTH ------------------------'); + for (int i = 0; i < accounts.length; i++) { + print( + '${accounts[i].accountId} (${accounts[i].currency}): ${accounts[i].token}'); + } + } final AuthorizeEntity? responseAuthorizeEntity = (await authRepository.authorize(token, tokenList: tokenList)) .authorize; From 9d9f946af848f903d55f874f6a3cb0014cf0f5c7 Mon Sep 17 00:00:00 2001 From: akhil-deriv Date: Thu, 30 May 2024 16:02:55 +0400 Subject: [PATCH 07/29] added a print statement --- .../lib/features/auth/services/deriv_auth_service.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart b/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart index e8fa144c2..37ef711bb 100644 --- a/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart +++ b/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart @@ -104,6 +104,7 @@ class DerivAuthService extends BaseAuthService { if (tokenList != null && tokenList.isNotEmpty) { print( '------------------------ RUNNING MULTI TOKEN AUTH ------------------------'); + print(token); for (int i = 0; i < accounts.length; i++) { print( '${accounts[i].accountId} (${accounts[i].currency}): ${accounts[i].token}'); From 20f834d85ec366d0d6d04fc42cd0d1e6d5ffcd4b Mon Sep 17 00:00:00 2001 From: akhil-deriv Date: Fri, 7 Jun 2024 00:09:30 +0400 Subject: [PATCH 08/29] added a print statement --- .../deriv_auth/lib/features/auth/cubit/deriv_auth_cubit.dart | 3 +++ 1 file changed, 3 insertions(+) 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 b34de146e..d4d6dd0f1 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 @@ -87,6 +87,7 @@ class DerivAuthCubit extends Cubit implements DerivAuthIO { @override Future tokenLogin(String token, {List? tokenList}) async { + print('-------------------- RUNNING TOKEN LOGIN ---------------------'); emit(DerivAuthLoadingState()); if (tokenList == null) { final List accountList = @@ -114,6 +115,8 @@ class DerivAuthCubit extends Cubit implements DerivAuthIO { request: request, userAgent: userAgent, ); + + ///TODO (John): Check if this has to be reset for every account change final LandingCompanyEntity landingCompanyEntity = await authService.getLandingCompany(authorizeEntity.country); _isUserMigrated = _checkUserMigrated(authorizeEntity); From 8287d8a6e9f13677ce019f02c84b965648484942 Mon Sep 17 00:00:00 2001 From: akhil-deriv Date: Mon, 10 Jun 2024 08:47:49 +0400 Subject: [PATCH 09/29] removed print statements --- .../lib/features/auth/cubit/deriv_auth_cubit.dart | 1 - .../lib/features/auth/services/deriv_auth_service.dart | 9 --------- 2 files changed, 10 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 d4d6dd0f1..a30fb3f31 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 @@ -87,7 +87,6 @@ class DerivAuthCubit extends Cubit implements DerivAuthIO { @override Future tokenLogin(String token, {List? tokenList}) async { - print('-------------------- RUNNING TOKEN LOGIN ---------------------'); emit(DerivAuthLoadingState()); if (tokenList == null) { final List accountList = diff --git a/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart b/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart index 37ef711bb..8151eb59d 100644 --- a/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart +++ b/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart @@ -101,15 +101,6 @@ class DerivAuthService extends BaseAuthService { String? refreshToken, }) async { try { - if (tokenList != null && tokenList.isNotEmpty) { - print( - '------------------------ RUNNING MULTI TOKEN AUTH ------------------------'); - print(token); - for (int i = 0; i < accounts.length; i++) { - print( - '${accounts[i].accountId} (${accounts[i].currency}): ${accounts[i].token}'); - } - } final AuthorizeEntity? responseAuthorizeEntity = (await authRepository.authorize(token, tokenList: tokenList)) .authorize; From 4bea0f3d8b969975d38740c625846a0a12268fd9 Mon Sep 17 00:00:00 2001 From: akhil-deriv Date: Tue, 11 Jun 2024 10:20:39 +0400 Subject: [PATCH 10/29] implemented reviewer suggestions --- .../lib/features/auth/cubit/deriv_auth_cubit.dart | 7 +++++-- .../features/auth/services/deriv_auth_service.dart | 14 ++++++++------ 2 files changed, 13 insertions(+), 8 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 a30fb3f31..ea759b76f 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 @@ -88,18 +88,21 @@ class DerivAuthCubit extends Cubit implements DerivAuthIO { @override Future tokenLogin(String token, {List? tokenList}) async { emit(DerivAuthLoadingState()); + List accountTokens = []; if (tokenList == null) { final List accountList = await authService.getLatestAccounts(); - tokenList = accountList + accountTokens = accountList .where((AccountModel account) => account.token != null && token != account.token) .map((AccountModel account) => account.token!) .toList(); + } else { + accountTokens = tokenList; } await _tokenLoginRequest( token, - tokenList: tokenList, + tokenList: accountTokens, accounts: await authService.getLatestAccounts(), ); } diff --git a/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart b/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart index 8151eb59d..689ad0367 100644 --- a/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart +++ b/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart @@ -46,6 +46,7 @@ class DerivAuthService extends BaseAuthService { Function? onInvalidJwtToken, }) async { try { + List _tokenList = []; final String jwtToken = await jwtService.getJwtToken(); final GetTokensResponseModel _response = await tokenService.getUserTokens( @@ -59,12 +60,13 @@ class DerivAuthService extends BaseAuthService { _filterSupportedAccounts(_response.accounts); final String? _defaultAccountToken = _supportedAccounts.first.token; - final List _tokenList = _supportedAccounts - .sublist(1) - .where((AccountModel account) => account.token != null) - .map((AccountModel account) => account.token!) - .toList(); - + if (_supportedAccounts.isNotEmpty && _defaultAccountToken != null) { + _tokenList = _supportedAccounts + .sublist(1) + .where((AccountModel account) => account.token != null) + .map((AccountModel account) => account.token!) + .toList(); + } if (_defaultAccountToken != null) { return login( _defaultAccountToken, From 08462d05db483b503c85904bb38d77d83e9bbdc2 Mon Sep 17 00:00:00 2001 From: akhil-deriv Date: Tue, 11 Jun 2024 11:43:56 +0400 Subject: [PATCH 11/29] fixed test case --- .../test/features/auth/cubit/deriv_auth_cubit_test.dart | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/deriv_auth/test/features/auth/cubit/deriv_auth_cubit_test.dart b/packages/deriv_auth/test/features/auth/cubit/deriv_auth_cubit_test.dart index e4c3d103e..b7a9a0403 100644 --- a/packages/deriv_auth/test/features/auth/cubit/deriv_auth_cubit_test.dart +++ b/packages/deriv_auth/test/features/auth/cubit/deriv_auth_cubit_test.dart @@ -287,8 +287,9 @@ void main() { Future>.value( [mockedAccountModel])); - when(() => service.login(any(), accounts: any(named: 'accounts'))) - .thenThrow(DerivAuthException( + when(() => service.login(any(), + accounts: any(named: 'accounts'), + tokenList: any(named: 'tokenList'))).thenThrow(DerivAuthException( message: 'message', type: AuthErrorType.invalidToken, )); From 2e903071f0e40d2b4532530aec1b45cb02bd72fd Mon Sep 17 00:00:00 2001 From: akhil-deriv Date: Fri, 28 Jun 2024 14:22:41 +0400 Subject: [PATCH 12/29] updated deriv_auth example --- .../login/repositories/example_login_repository.dart | 5 ++++- .../lib/features/login/services/example_login_service.dart | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/deriv_auth/example/lib/features/login/repositories/example_login_repository.dart b/packages/deriv_auth/example/lib/features/login/repositories/example_login_repository.dart index 2e7f72a29..60eb5eb98 100644 --- a/packages/deriv_auth/example/lib/features/login/repositories/example_login_repository.dart +++ b/packages/deriv_auth/example/lib/features/login/repositories/example_login_repository.dart @@ -3,7 +3,10 @@ import 'package:deriv_auth/deriv_auth.dart'; class ExampleLoginRepository implements BaseAuthRepository { @override - Future authorize(String? token) => + Future authorize( + String? token, { + List? tokenList, + }) => Future.value(const AuthorizeResponseEntity()); @override diff --git a/packages/deriv_auth/example/lib/features/login/services/example_login_service.dart b/packages/deriv_auth/example/lib/features/login/services/example_login_service.dart index 63c832a4f..5819366e9 100644 --- a/packages/deriv_auth/example/lib/features/login/services/example_login_service.dart +++ b/packages/deriv_auth/example/lib/features/login/services/example_login_service.dart @@ -24,6 +24,7 @@ class ExampleLoginService extends BaseAuthService { Future login( String token, { required List accounts, + List? tokenList, String? signupProvider, String? refreshToken, }) async => From 80c75f0b21ffbc6d00e92ae50e9eebc049083da6 Mon Sep 17 00:00:00 2001 From: akhil-deriv Date: Fri, 28 Jun 2024 15:03:01 +0400 Subject: [PATCH 13/29] updated package errors --- packages/update_checker/example/lib/update_bloc_page.dart | 2 +- packages/update_checker/example/lib/update_checker_page.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/update_checker/example/lib/update_bloc_page.dart b/packages/update_checker/example/lib/update_bloc_page.dart index 55b0b079f..b56059d2c 100644 --- a/packages/update_checker/example/lib/update_bloc_page.dart +++ b/packages/update_checker/example/lib/update_bloc_page.dart @@ -10,7 +10,7 @@ class UpdateBlocPage extends StatefulWidget { class _UpdateBlocPageState extends State { final UpdateBloc updateBloc = - UpdateBloc(firebaseRepository: const FirebaseRemoteConfigRepository()); + UpdateBloc(firebaseRepository: FirebaseRemoteConfigRepository()); @override Widget build(BuildContext context) => Scaffold( diff --git a/packages/update_checker/example/lib/update_checker_page.dart b/packages/update_checker/example/lib/update_checker_page.dart index 1d54f4043..672a432a0 100644 --- a/packages/update_checker/example/lib/update_checker_page.dart +++ b/packages/update_checker/example/lib/update_checker_page.dart @@ -10,7 +10,7 @@ class UpdateCheckerPage extends StatelessWidget { ), body: Builder( builder: (BuildContext context) => UpdateChecker( - firebaseRepository: const FirebaseRemoteConfigRepository(), + firebaseRepository: FirebaseRemoteConfigRepository(), onNotAvailable: () => _showSnackBar( context, 'Update not available', From d387779e51dc8fce1a77c70ff0b988c4216272c3 Mon Sep 17 00:00:00 2001 From: akhil-deriv Date: Mon, 1 Jul 2024 23:01:30 +0400 Subject: [PATCH 14/29] temporarily commented trackers --- .../lib/features/auth/cubit/deriv_auth_cubit.dart | 7 ++++--- 1 file changed, 4 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 b6634b85c..2680505a0 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 @@ -135,12 +135,12 @@ class DerivAuthCubit extends Cubit userAgent: userAgent, ); - ///TODO (John): Check if this has to be reset for every account change final LandingCompanyEntity landingCompanyEntity = await authService.getLandingCompany(authorizeEntity.country); _isUserMigrated = _checkUserMigrated(authorizeEntity); - trackLoginFinished(); + ///TODO (John): Uncomment this when the tracking is ready + // trackLoginFinished(); emit(DerivAuthLoggedInState( DerivAuthModel( @@ -169,7 +169,8 @@ class DerivAuthCubit extends Cubit await authService.getLandingCompany(authorizeEntity.country); _isUserMigrated = _checkUserMigrated(authorizeEntity); - trackLoginFinished(); + ///TODO (John): Uncomment this when the tracking is ready + // trackLoginFinished(); emit( DerivAuthLoggedInState( From 4503c81e657358b9904c406305fd8288a5d7316f Mon Sep 17 00:00:00 2001 From: akhil-deriv Date: Wed, 3 Jul 2024 14:07:06 +0400 Subject: [PATCH 15/29] updated pubspec --- .../services/social_web_view_service.dart | 1 - pubspec.lock | 36 +++++++++---------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/packages/deriv_auth/lib/features/social_auth/services/social_web_view_service.dart b/packages/deriv_auth/lib/features/social_auth/services/social_web_view_service.dart index c4353f8af..98cc5c7f5 100644 --- a/packages/deriv_auth/lib/features/social_auth/services/social_web_view_service.dart +++ b/packages/deriv_auth/lib/features/social_auth/services/social_web_view_service.dart @@ -1,5 +1,4 @@ import 'dart:async'; - import 'package:app_links/app_links.dart'; import 'package:deriv_auth/deriv_auth.dart'; import 'package:deriv_web_view/web_view.dart'; diff --git a/pubspec.lock b/pubspec.lock index 5a8d1a5b1..ba4e85d35 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -13,10 +13,10 @@ packages: dependency: transitive description: name: args - sha256: eef6c46b622e0494a36c5a12d10d77fb4e855501a91c1b9ef9339326e58f0596 + sha256: "7cf60b9f0cc88203c5a190b4cd62a99feea42759a7fa695010eb5de1c0b2252a" url: "https://pub.dev" source: hosted - version: "2.4.2" + version: "2.5.0" async: dependency: transitive description: @@ -53,10 +53,10 @@ packages: dependency: transitive description: name: cli_util - sha256: b8db3080e59b2503ca9e7922c3df2072cf13992354d5e944074ffa836fba43b7 + sha256: c05b7406fdabc7a49a3929d4af76bcaccbbffcbcdcf185b082e1ae07da323d19 url: "https://pub.dev" source: hosted - version: "0.4.0" + version: "0.4.1" collection: dependency: transitive description: @@ -125,18 +125,18 @@ packages: dependency: transitive description: name: json_annotation - sha256: b10a7b2ff83d83c777edba3c6a0f97045ddadd56c944e1a23a3fdf43a1bf4467 + sha256: "1ce844379ca14835a50d2f019a3099f419082cfdd231cd86a142af94dd5c6bb1" url: "https://pub.dev" source: hosted - version: "4.8.1" + version: "4.9.0" matcher: dependency: transitive description: name: matcher - sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e" + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb url: "https://pub.dev" source: hosted - version: "0.12.16" + version: "0.12.16+1" melos: dependency: "direct dev" description: @@ -149,10 +149,10 @@ packages: dependency: transitive description: name: meta - sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 + sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7 url: "https://pub.dev" source: hosted - version: "1.11.0" + version: "1.15.0" mustache_template: dependency: transitive description: @@ -165,18 +165,18 @@ packages: dependency: transitive description: name: path - sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" url: "https://pub.dev" source: hosted - version: "1.8.3" + version: "1.9.0" platform: dependency: transitive description: name: platform - sha256: "0a279f0707af40c890e80b1e9df8bb761694c074ba7e1d4ab1bc4b728e200b59" + sha256: "12220bb4b65720483f8fa9450b4332347737cf8213dd2840d8b2c823e47243ec" url: "https://pub.dev" source: hosted - version: "3.1.3" + version: "3.1.4" pool: dependency: transitive description: @@ -277,10 +277,10 @@ packages: dependency: transitive description: name: test_api - sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" + sha256: "2419f20b0c8677b2d67c8ac4d1ac7372d862dc6c460cdbb052b40155408cd794" url: "https://pub.dev" source: hosted - version: "0.6.1" + version: "0.7.1" typed_data: dependency: transitive description: @@ -309,9 +309,9 @@ packages: dependency: transitive description: name: yaml_edit - sha256: "1579d4a0340a83cf9e4d580ea51a16329c916973bffd5bd4b45e911b25d46bfd" + sha256: e9c1a3543d2da0db3e90270dbb1e4eebc985ee5e3ffe468d83224472b2194a5f url: "https://pub.dev" source: hosted - version: "2.1.1" + version: "2.2.1" sdks: dart: ">=3.0.0 <4.0.0" From df5b81d5ba4c3cf0ddffac806a314e322bf35051 Mon Sep 17 00:00:00 2001 From: akhil-deriv Date: Wed, 3 Jul 2024 20:21:07 +0400 Subject: [PATCH 16/29] implemented new multi token authorization change --- .../features/auth/cubit/deriv_auth_cubit.dart | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 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 049b221f9..aa1f5599e 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 @@ -107,15 +107,17 @@ class DerivAuthCubit extends Cubit final List accountList = await authService.getLatestAccounts(); accountTokens = accountList - .where((AccountModel account) => - account.token != null && token != account.token) + .where((AccountModel account) => account.token != null) .map((AccountModel account) => account.token!) .toList(); } else { accountTokens = tokenList; } + if (!accountTokens.contains(token)) { + accountTokens.add(token); + } await _tokenLoginRequest( - token, + 'MULTI', tokenList: accountTokens, accounts: await authService.getLatestAccounts(), ); @@ -202,14 +204,16 @@ class DerivAuthCubit extends Cubit return; } else { tokenList = accountList - .where((AccountModel account) => - account.token != null && defaultAccountToken != account.token) + .where((AccountModel account) => account.token != null) .map((AccountModel account) => account.token!) .toList(); - } + if (!tokenList.contains(defaultAccountToken)) { + tokenList.add(defaultAccountToken); + } + } await _tokenLoginRequest( - defaultAccountToken, + 'MULTI', accounts: accountList, tokenList: tokenList, ); From 0a1e1422c2ad21e5142c4da26367f724a8041b11 Mon Sep 17 00:00:00 2001 From: akhil-deriv Date: Thu, 4 Jul 2024 13:53:57 +0400 Subject: [PATCH 17/29] updated deriv auth authorize methods --- .../features/auth/cubit/deriv_auth_cubit.dart | 58 ++++++++++++++----- .../lib/features/auth/deriv_auth_io.dart | 10 +++- .../auth/cubit/deriv_auth_cubit_test.dart | 34 +++++------ 3 files changed, 67 insertions(+), 35 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 aa1f5599e..14673bbec 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 @@ -100,25 +100,32 @@ class DerivAuthCubit extends Cubit } @override - Future tokenLogin(String token, {List? tokenList}) async { + Future multiTokenLogin(String? token) async { emit(DerivAuthLoadingState()); - List accountTokens = []; - if (tokenList == null) { - final List accountList = - await authService.getLatestAccounts(); - accountTokens = accountList - .where((AccountModel account) => account.token != null) - .map((AccountModel account) => account.token!) - .toList(); - } else { - accountTokens = tokenList; - } - if (!accountTokens.contains(token)) { - accountTokens.add(token); + + final List accountList = + await authService.getLatestAccounts(); + final List tokenList = accountList + .where((AccountModel account) => account.token != null) + .map((AccountModel account) => account.token!) + .toList(); + + if (token != null && !tokenList.contains(token)) { + tokenList.add(token); } await _tokenLoginRequest( 'MULTI', - tokenList: accountTokens, + tokenList: tokenList, + accounts: accountList, + ); + } + + @override + Future tokenLogin(String token) async { + emit(DerivAuthLoadingState()); + + await _tokenLoginRequest( + token, accounts: await authService.getLatestAccounts(), ); } @@ -189,7 +196,7 @@ class DerivAuthCubit extends Cubit } @override - Future authorizeDefaultAccount() async { + Future multiAuthorizeDefaultAccount() async { emit(DerivAuthLoadingState()); List tokenList = []; @@ -219,6 +226,25 @@ class DerivAuthCubit extends Cubit ); } + @override + Future authorizeDefaultAccount() async { + emit(DerivAuthLoadingState()); + + final String? defaultAccountToken = + (await authService.getDefaultAccount())?.token; + + if (defaultAccountToken == null) { + emit(DerivAuthLoggedOutState()); + + return; + } + + await _tokenLoginRequest( + defaultAccountToken, + accounts: await authService.getLatestAccounts(), + ); + } + @override Future logout() async { if (state is DerivAuthLoggedOutState) { diff --git a/packages/deriv_auth/lib/features/auth/deriv_auth_io.dart b/packages/deriv_auth/lib/features/auth/deriv_auth_io.dart index c72401b34..b3fe99bad 100644 --- a/packages/deriv_auth/lib/features/auth/deriv_auth_io.dart +++ b/packages/deriv_auth/lib/features/auth/deriv_auth_io.dart @@ -27,14 +27,22 @@ abstract class DerivAuthIO { }); /// Log user in with [token] after reset password or sign up. - Future tokenLogin(String token, {List? tokenList}); + @deprecated + Future tokenLogin(String token); + + /// Log user in with multi token authorization after reset password or sign up. + Future multiTokenLogin(String? token); /// Log user out. Future logout(); /// Log default user in. + @deprecated Future authorizeDefaultAccount(); + /// Log default user in using multi authorization. + Future multiAuthorizeDefaultAccount(); + /// Deriv auth output. Stream get output; } diff --git a/packages/deriv_auth/test/features/auth/cubit/deriv_auth_cubit_test.dart b/packages/deriv_auth/test/features/auth/cubit/deriv_auth_cubit_test.dart index cf14654cd..90518157b 100644 --- a/packages/deriv_auth/test/features/auth/cubit/deriv_auth_cubit_test.dart +++ b/packages/deriv_auth/test/features/auth/cubit/deriv_auth_cubit_test.dart @@ -91,11 +91,9 @@ void main() { when(() => service.getLandingCompany(any())).thenAnswer((_) => Future.value(const LandingCompanyEntity())); - when(() => service - .login(any(), - accounts: any(named: 'accounts'), - tokenList: [])).thenAnswer( - (_) => Future.value(mockedValidAuthorizeEntity)); + when(() => service.login(any(), accounts: any(named: 'accounts'))) + .thenAnswer((_) => + Future.value(mockedValidAuthorizeEntity)); final List> expectedResponse = >[ @@ -269,11 +267,9 @@ void main() { Future>.value( [mockedAccountModel])); - when(() => service - .login(any(), - accounts: any(named: 'accounts'), - tokenList: [])).thenAnswer( - (_) => Future.value(mockedValidAuthorizeEntity)); + when(() => service.login(any(), accounts: any(named: 'accounts'))) + .thenAnswer((_) => + Future.value(mockedValidAuthorizeEntity)); final List> expectedResponse = >[ @@ -289,11 +285,10 @@ void main() { emitsInOrder(expectedResponse), ); - authCubit.tokenLogin(_token, tokenList: []); + authCubit.tokenLogin(_token); verify( - () => service.login(any(), - accounts: any(named: 'accounts'), tokenList: []), + () => service.login(any(), accounts: any(named: 'accounts')), ).called(1); }); @@ -306,9 +301,10 @@ void main() { Future>.value( [mockedAccountModel])); - when(() => service.login(any(), - accounts: any(named: 'accounts'), - tokenList: any(named: 'tokenList'))).thenThrow(DerivAuthException( + when(() => service.login( + any(), + accounts: any(named: 'accounts'), + )).thenThrow(DerivAuthException( message: 'message', type: AuthErrorType.invalidToken, )); @@ -327,8 +323,10 @@ void main() { authCubit.tokenLogin(_token); verify( - () => service.login(any(), - accounts: any(named: 'accounts'), tokenList: []), + () => service.login( + any(), + accounts: any(named: 'accounts'), + ), ).called(1); }); From e829ad0917542d2bcfa92205bfc6b0ddc295f0d0 Mon Sep 17 00:00:00 2001 From: akhil-deriv Date: Sun, 14 Jul 2024 23:40:18 +0400 Subject: [PATCH 18/29] updated loginRequest in Deriv Auth to support multi token authorization --- .../lib/features/auth/cubit/deriv_auth_cubit.dart | 2 +- packages/deriv_auth/lib/features/auth/deriv_auth_io.dart | 2 +- .../lib/features/auth/services/deriv_auth_service.dart | 9 +++------ 3 files changed, 5 insertions(+), 8 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 14673bbec..e95338d23 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 @@ -196,7 +196,7 @@ class DerivAuthCubit extends Cubit } @override - Future multiAuthorizeDefaultAccount() async { + Future multiAuthorizeAccounts() async { emit(DerivAuthLoadingState()); List tokenList = []; diff --git a/packages/deriv_auth/lib/features/auth/deriv_auth_io.dart b/packages/deriv_auth/lib/features/auth/deriv_auth_io.dart index b3fe99bad..e04f03111 100644 --- a/packages/deriv_auth/lib/features/auth/deriv_auth_io.dart +++ b/packages/deriv_auth/lib/features/auth/deriv_auth_io.dart @@ -41,7 +41,7 @@ abstract class DerivAuthIO { Future authorizeDefaultAccount(); /// Log default user in using multi authorization. - Future multiAuthorizeDefaultAccount(); + Future multiAuthorizeAccounts(); /// Deriv auth output. Stream get output; diff --git a/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart b/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart index a34ad8d39..73ba4fd61 100644 --- a/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart +++ b/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart @@ -42,17 +42,14 @@ class DerivAuthService extends BaseAuthService { final List _supportedAccounts = _filterSupportedAccounts(_response.accounts); - final String? _defaultAccountToken = _supportedAccounts.first.token; - if (_supportedAccounts.isNotEmpty && _defaultAccountToken != null) { + if (_supportedAccounts.isNotEmpty) { _tokenList = _supportedAccounts - .sublist(1) .where((AccountModel account) => account.token != null) .map((AccountModel account) => account.token!) .toList(); - } - if (_defaultAccountToken != null) { + return login( - _defaultAccountToken, + 'MULTI', tokenList: _tokenList.isEmpty ? null : _tokenList, accounts: _supportedAccounts, signupProvider: request.signupProvider, From 4607a6f590bfa3625a315eaeca3fa8d366026a13 Mon Sep 17 00:00:00 2001 From: akhil-deriv Date: Mon, 15 Jul 2024 11:31:11 +0400 Subject: [PATCH 19/29] uncommented login tracking --- .../deriv_auth/lib/features/auth/cubit/deriv_auth_cubit.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 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 e95338d23..4a9357be2 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 @@ -146,7 +146,7 @@ class DerivAuthCubit extends Cubit _isUserMigrated = _checkUserMigrated(authorizeEntity); ///TODO (John): Uncomment this when the tracking is ready - // trackLoginFinished(); + trackLoginFinished(); emit(DerivAuthLoggedInState( DerivAuthModel( @@ -176,7 +176,7 @@ class DerivAuthCubit extends Cubit _isUserMigrated = _checkUserMigrated(authorizeEntity); ///TODO (John): Uncomment this when the tracking is ready - // trackLoginFinished(); + trackLoginFinished(); emit( DerivAuthLoggedInState( From a18b717b9c4fbd897647e481005132205f581962 Mon Sep 17 00:00:00 2001 From: akhil-deriv Date: Mon, 15 Jul 2024 11:33:55 +0400 Subject: [PATCH 20/29] removed related TODO's --- .../deriv_auth/lib/features/auth/cubit/deriv_auth_cubit.dart | 2 -- 1 file changed, 2 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 4a9357be2..339c69fd6 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 @@ -145,7 +145,6 @@ class DerivAuthCubit extends Cubit await authService.getLandingCompany(authorizeEntity.country); _isUserMigrated = _checkUserMigrated(authorizeEntity); - ///TODO (John): Uncomment this when the tracking is ready trackLoginFinished(); emit(DerivAuthLoggedInState( @@ -175,7 +174,6 @@ class DerivAuthCubit extends Cubit await authService.getLandingCompany(authorizeEntity.country); _isUserMigrated = _checkUserMigrated(authorizeEntity); - ///TODO (John): Uncomment this when the tracking is ready trackLoginFinished(); emit( From 2c0b0a5db437e62841179898706df01cae7396c9 Mon Sep 17 00:00:00 2001 From: akhil-deriv Date: Wed, 24 Jul 2024 15:54:40 +0400 Subject: [PATCH 21/29] updated the naming for multiTokenLogin --- .../lib/features/auth/cubit/deriv_auth_cubit.dart | 2 +- packages/deriv_auth/lib/features/auth/deriv_auth_io.dart | 6 ++++-- 2 files changed, 5 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 339c69fd6..d77e0f266 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 @@ -100,7 +100,7 @@ class DerivAuthCubit extends Cubit } @override - Future multiTokenLogin(String? token) async { + Future multiTokenAuthorize(String? token) async { emit(DerivAuthLoadingState()); final List accountList = diff --git a/packages/deriv_auth/lib/features/auth/deriv_auth_io.dart b/packages/deriv_auth/lib/features/auth/deriv_auth_io.dart index e04f03111..69aef550e 100644 --- a/packages/deriv_auth/lib/features/auth/deriv_auth_io.dart +++ b/packages/deriv_auth/lib/features/auth/deriv_auth_io.dart @@ -30,8 +30,10 @@ abstract class DerivAuthIO { @deprecated Future tokenLogin(String token); - /// Log user in with multi token authorization after reset password or sign up. - Future multiTokenLogin(String? token); + /// Log user in with multi token authorization + /// Add [token] to the list of authorized tokens. + /// And authorize the user with the new list of tokens. + Future multiTokenAuthorize(String? token); /// Log user out. Future logout(); From ea0753e4a1283c9ccdd48fc48b65198c011e2086 Mon Sep 17 00:00:00 2001 From: akhil-deriv Date: Wed, 24 Jul 2024 17:10:50 +0400 Subject: [PATCH 22/29] updated naming and documentation for mutiAuthorize --- .../deriv_auth/lib/features/auth/cubit/deriv_auth_cubit.dart | 2 +- packages/deriv_auth/lib/features/auth/deriv_auth_io.dart | 4 ++-- 2 files changed, 3 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 d77e0f266..1fdb0d209 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 @@ -194,7 +194,7 @@ class DerivAuthCubit extends Cubit } @override - Future multiAuthorizeAccounts() async { + Future multiAuthorizeAllAccounts() async { emit(DerivAuthLoadingState()); List tokenList = []; diff --git a/packages/deriv_auth/lib/features/auth/deriv_auth_io.dart b/packages/deriv_auth/lib/features/auth/deriv_auth_io.dart index 69aef550e..9acd6128f 100644 --- a/packages/deriv_auth/lib/features/auth/deriv_auth_io.dart +++ b/packages/deriv_auth/lib/features/auth/deriv_auth_io.dart @@ -42,8 +42,8 @@ abstract class DerivAuthIO { @deprecated Future authorizeDefaultAccount(); - /// Log default user in using multi authorization. - Future multiAuthorizeAccounts(); + /// Uses multi authorization for all user accounts. + Future multiAuthorizeAllAccounts(); /// Deriv auth output. Stream get output; From 4c5760281d50a7801754476df7a9be84b6178d92 Mon Sep 17 00:00:00 2001 From: akhil-deriv Date: Thu, 25 Jul 2024 02:00:55 +0400 Subject: [PATCH 23/29] added optional multi token for login --- .../login/services/example_login_service.dart | 1 + .../features/auth/cubit/deriv_auth_cubit.dart | 8 +++ .../lib/features/auth/deriv_auth_io.dart | 3 ++ .../auth/services/base_auth_service.dart | 1 + .../auth/services/deriv_auth_service.dart | 53 +++++++++++++------ 5 files changed, 49 insertions(+), 17 deletions(-) diff --git a/packages/deriv_auth/example/lib/features/login/services/example_login_service.dart b/packages/deriv_auth/example/lib/features/login/services/example_login_service.dart index 72b55b6af..8505786b6 100644 --- a/packages/deriv_auth/example/lib/features/login/services/example_login_service.dart +++ b/packages/deriv_auth/example/lib/features/login/services/example_login_service.dart @@ -18,6 +18,7 @@ class ExampleLoginService extends BaseAuthService { Future onLoginRequest({ required GetTokensRequestModel request, String? userAgent, + bool? useMultiToken, }) async => const AuthorizeEntity(); 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 1fdb0d209..27b3cde1c 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 @@ -42,6 +42,7 @@ class DerivAuthCubit extends Cubit required String password, String? otp, String? userAgent, + bool? useMultiToken, }) async { trackLoginWithEmailAndPassword(); @@ -56,6 +57,7 @@ class DerivAuthCubit extends Cubit ), isSocialLogin: false, userAgent: userAgent, + useMultiToken: useMultiToken, ); } @@ -65,6 +67,7 @@ class DerivAuthCubit extends Cubit final String? signupProvider, String? otp, String? userAgent, + bool? useMultiToken, }) async { emit(DerivAuthLoadingState()); @@ -77,6 +80,7 @@ class DerivAuthCubit extends Cubit ), isSocialLogin: true, userAgent: userAgent, + useMultiToken: useMultiToken, ); } @@ -85,6 +89,7 @@ class DerivAuthCubit extends Cubit required SocialAuthDto socialAuthDto, String? otp, String? userAgent, + bool? useMultiToken, }) async { emit(DerivAuthLoadingState()); @@ -96,6 +101,7 @@ class DerivAuthCubit extends Cubit ), isSocialLogin: true, userAgent: userAgent, + useMultiToken: useMultiToken, ); } @@ -134,11 +140,13 @@ class DerivAuthCubit extends Cubit required GetTokensRequestModel request, required bool isSocialLogin, String? userAgent, + bool? useMultiToken, }) async { try { final AuthorizeEntity authorizeEntity = await authService.onLoginRequest( request: request, userAgent: userAgent, + useMultiToken: useMultiToken, ); final LandingCompanyEntity landingCompanyEntity = diff --git a/packages/deriv_auth/lib/features/auth/deriv_auth_io.dart b/packages/deriv_auth/lib/features/auth/deriv_auth_io.dart index 9acd6128f..cbf8560af 100644 --- a/packages/deriv_auth/lib/features/auth/deriv_auth_io.dart +++ b/packages/deriv_auth/lib/features/auth/deriv_auth_io.dart @@ -9,6 +9,7 @@ abstract class DerivAuthIO { required String email, required String password, String? otp, + bool? useMultiToken, }); /// Social login/signup with [oneAllConnectionToken] using one-all service. @@ -18,12 +19,14 @@ abstract class DerivAuthIO { Future socialLogin({ required String oneAllConnectionToken, String? otp, + bool? useMultiToken, }); /// Social login/signup using custom in-house service. Future socialAuth({ required SocialAuthDto socialAuthDto, String? otp, + bool? useMultiToken, }); /// Log user in with [token] after reset password or sign up. diff --git a/packages/deriv_auth/lib/features/auth/services/base_auth_service.dart b/packages/deriv_auth/lib/features/auth/services/base_auth_service.dart index 46c498638..14f7da89f 100644 --- a/packages/deriv_auth/lib/features/auth/services/base_auth_service.dart +++ b/packages/deriv_auth/lib/features/auth/services/base_auth_service.dart @@ -33,6 +33,7 @@ abstract class BaseAuthService { Future onLoginRequest({ required GetTokensRequestModel request, String? userAgent, + bool? useMultiToken, }); /// Log in a user with [token]. diff --git a/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart b/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart index caf83dcbb..41bcca005 100644 --- a/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart +++ b/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart @@ -27,6 +27,7 @@ class DerivAuthService extends BaseAuthService { required GetTokensRequestModel request, String? userAgent, Function? onInvalidJwtToken, + bool? useMultiToken, }) async { try { List _tokenList = []; @@ -42,24 +43,42 @@ class DerivAuthService extends BaseAuthService { final List _supportedAccounts = _filterSupportedAccounts(_response.accounts); - if (_supportedAccounts.isNotEmpty) { - _tokenList = _supportedAccounts - .where((AccountModel account) => account.token != null) - .map((AccountModel account) => account.token!) - .toList(); - - return login( - 'MULTI', - tokenList: _tokenList.isEmpty ? null : _tokenList, - accounts: _supportedAccounts, - signupProvider: request.signupProvider, - refreshToken: _response.refreshToken, - ); + if (useMultiToken == null || useMultiToken == false) { + final String? _defaultAccountToken = _supportedAccounts.first.token; + + if (_defaultAccountToken != null) { + return login( + _defaultAccountToken, + accounts: _supportedAccounts, + signupProvider: request.signupProvider, + refreshToken: _response.refreshToken, + ); + } else { + throw DerivAuthException( + message: accountUnavailableError, + type: AuthErrorType.accountUnavailable, + ); + } } else { - throw DerivAuthException( - message: accountUnavailableError, - type: AuthErrorType.accountUnavailable, - ); + if (_supportedAccounts.isNotEmpty) { + _tokenList = _supportedAccounts + .where((AccountModel account) => account.token != null) + .map((AccountModel account) => account.token!) + .toList(); + + return login( + 'MULTI', + tokenList: _tokenList.isEmpty ? null : _tokenList, + accounts: _supportedAccounts, + signupProvider: request.signupProvider, + refreshToken: _response.refreshToken, + ); + } else { + throw DerivAuthException( + message: accountUnavailableError, + type: AuthErrorType.accountUnavailable, + ); + } } } on HTTPClientException catch (error) { if (error.errorCode == invalidJwtTokenError) { From 2a5af109b7d24f6e5390e739b33e44cda0e6f45a Mon Sep 17 00:00:00 2001 From: akhil-deriv Date: Thu, 25 Jul 2024 13:41:11 +0400 Subject: [PATCH 24/29] made useMultiToken default to false --- .../features/login/services/example_login_service.dart | 2 +- .../lib/features/auth/cubit/deriv_auth_cubit.dart | 8 ++++---- packages/deriv_auth/lib/features/auth/deriv_auth_io.dart | 6 +++--- .../lib/features/auth/services/base_auth_service.dart | 2 +- .../lib/features/auth/services/deriv_auth_service.dart | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/deriv_auth/example/lib/features/login/services/example_login_service.dart b/packages/deriv_auth/example/lib/features/login/services/example_login_service.dart index 8505786b6..8e912259a 100644 --- a/packages/deriv_auth/example/lib/features/login/services/example_login_service.dart +++ b/packages/deriv_auth/example/lib/features/login/services/example_login_service.dart @@ -18,7 +18,7 @@ class ExampleLoginService extends BaseAuthService { Future onLoginRequest({ required GetTokensRequestModel request, String? userAgent, - bool? useMultiToken, + bool useMultiToken = false, }) async => const AuthorizeEntity(); 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 27b3cde1c..89d5e5bba 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 @@ -42,7 +42,7 @@ class DerivAuthCubit extends Cubit required String password, String? otp, String? userAgent, - bool? useMultiToken, + bool useMultiToken = false, }) async { trackLoginWithEmailAndPassword(); @@ -67,7 +67,7 @@ class DerivAuthCubit extends Cubit final String? signupProvider, String? otp, String? userAgent, - bool? useMultiToken, + bool useMultiToken = false, }) async { emit(DerivAuthLoadingState()); @@ -89,7 +89,7 @@ class DerivAuthCubit extends Cubit required SocialAuthDto socialAuthDto, String? otp, String? userAgent, - bool? useMultiToken, + bool useMultiToken = false, }) async { emit(DerivAuthLoadingState()); @@ -140,7 +140,7 @@ class DerivAuthCubit extends Cubit required GetTokensRequestModel request, required bool isSocialLogin, String? userAgent, - bool? useMultiToken, + bool useMultiToken = false, }) async { try { final AuthorizeEntity authorizeEntity = await authService.onLoginRequest( diff --git a/packages/deriv_auth/lib/features/auth/deriv_auth_io.dart b/packages/deriv_auth/lib/features/auth/deriv_auth_io.dart index cbf8560af..5500ef95b 100644 --- a/packages/deriv_auth/lib/features/auth/deriv_auth_io.dart +++ b/packages/deriv_auth/lib/features/auth/deriv_auth_io.dart @@ -9,7 +9,7 @@ abstract class DerivAuthIO { required String email, required String password, String? otp, - bool? useMultiToken, + bool useMultiToken = false, }); /// Social login/signup with [oneAllConnectionToken] using one-all service. @@ -19,14 +19,14 @@ abstract class DerivAuthIO { Future socialLogin({ required String oneAllConnectionToken, String? otp, - bool? useMultiToken, + bool useMultiToken = false, }); /// Social login/signup using custom in-house service. Future socialAuth({ required SocialAuthDto socialAuthDto, String? otp, - bool? useMultiToken, + bool useMultiToken = false, }); /// Log user in with [token] after reset password or sign up. diff --git a/packages/deriv_auth/lib/features/auth/services/base_auth_service.dart b/packages/deriv_auth/lib/features/auth/services/base_auth_service.dart index 14f7da89f..7dd103c59 100644 --- a/packages/deriv_auth/lib/features/auth/services/base_auth_service.dart +++ b/packages/deriv_auth/lib/features/auth/services/base_auth_service.dart @@ -33,7 +33,7 @@ abstract class BaseAuthService { Future onLoginRequest({ required GetTokensRequestModel request, String? userAgent, - bool? useMultiToken, + bool useMultiToken = false, }); /// Log in a user with [token]. diff --git a/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart b/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart index 41bcca005..af4ce56b0 100644 --- a/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart +++ b/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart @@ -27,7 +27,7 @@ class DerivAuthService extends BaseAuthService { required GetTokensRequestModel request, String? userAgent, Function? onInvalidJwtToken, - bool? useMultiToken, + bool useMultiToken = false, }) async { try { List _tokenList = []; @@ -43,7 +43,7 @@ class DerivAuthService extends BaseAuthService { final List _supportedAccounts = _filterSupportedAccounts(_response.accounts); - if (useMultiToken == null || useMultiToken == false) { + if (useMultiToken == false) { final String? _defaultAccountToken = _supportedAccounts.first.token; if (_defaultAccountToken != null) { From 8f3f49aace17f33c2b651987f71e9cf2ef4f9d27 Mon Sep 17 00:00:00 2001 From: akhil-deriv Date: Thu, 25 Jul 2024 13:48:06 +0400 Subject: [PATCH 25/29] add a list empty check when getting defaultAccountID --- .../lib/features/auth/services/deriv_auth_service.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart b/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart index af4ce56b0..5732dfa0c 100644 --- a/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart +++ b/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart @@ -44,7 +44,9 @@ class DerivAuthService extends BaseAuthService { _filterSupportedAccounts(_response.accounts); if (useMultiToken == false) { - final String? _defaultAccountToken = _supportedAccounts.first.token; + final String? _defaultAccountToken = _supportedAccounts.isNotEmpty + ? _supportedAccounts.first.token + : null; if (_defaultAccountToken != null) { return login( From 9779a7918de99bb154e1203a465c16ece2eef4f9 Mon Sep 17 00:00:00 2001 From: akhil-deriv Date: Thu, 25 Jul 2024 13:53:23 +0400 Subject: [PATCH 26/29] code optimization --- .../lib/features/auth/services/deriv_auth_service.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart b/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart index 5732dfa0c..a4b63163a 100644 --- a/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart +++ b/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart @@ -64,8 +64,8 @@ class DerivAuthService extends BaseAuthService { } else { if (_supportedAccounts.isNotEmpty) { _tokenList = _supportedAccounts - .where((AccountModel account) => account.token != null) - .map((AccountModel account) => account.token!) + .map((AccountModel account) => account.token) + .whereNotNull() .toList(); return login( From 9c33fbffd0f295aadebaca2cb908c8d6d79a0f83 Mon Sep 17 00:00:00 2001 From: akhil-deriv Date: Wed, 28 Aug 2024 23:23:14 +0400 Subject: [PATCH 27/29] added a fix for how we save the token in the enhanced authorize entity --- .../lib/features/auth/services/deriv_auth_service.dart | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart b/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart index a4b63163a..ae3ce63a3 100644 --- a/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart +++ b/packages/deriv_auth/lib/features/auth/services/deriv_auth_service.dart @@ -110,6 +110,12 @@ class DerivAuthService extends BaseAuthService { _checkAuthorizeValidity(responseAuthorizeEntity); + /// If the token is 'MULTI' then the last token in the list will be used + /// as the token for the account as this is the most recently added token. + /// Else we can used the provided token. + final String _token = + token.compareTo('MULTI') == 0 ? tokenList?.last ?? '' : token; + final AuthorizeEntity _enhancedAuthorizeEntity = responseAuthorizeEntity!.copyWith( signupProvider: signupProvider, @@ -124,7 +130,7 @@ class DerivAuthService extends BaseAuthService { ) .firstOrNull ?.token ?? - token, + _token, ), ) .toList(), From cb521f640c01eb8db83ba6d7d7a95e2a69ef340f Mon Sep 17 00:00:00 2001 From: akhil-deriv Date: Wed, 4 Sep 2024 16:35:36 +0400 Subject: [PATCH 28/29] added loginId for logout --- .../lib/features/auth/repository/base_auth_repository.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/deriv_auth/lib/features/auth/repository/base_auth_repository.dart b/packages/deriv_auth/lib/features/auth/repository/base_auth_repository.dart index 5e0203ad3..73e58b950 100644 --- a/packages/deriv_auth/lib/features/auth/repository/base_auth_repository.dart +++ b/packages/deriv_auth/lib/features/auth/repository/base_auth_repository.dart @@ -14,7 +14,9 @@ abstract class BaseAuthRepository { Future onLogin(AuthorizeEntity authorizeEntity); /// Log user out. - Future logout(); + Future logout({ + String? loginId, + }); /// Functionality on user logs out. Future onLogout(); From 978ea385e0c4d398cd81ba0bbb4b832284bc0b9a Mon Sep 17 00:00:00 2001 From: akhil-deriv Date: Wed, 4 Sep 2024 23:10:12 +0400 Subject: [PATCH 29/29] added loginId for passkeys for multiToken --- .../base_deriv_passkeys_data_source.dart | 6 ++-- .../deriv_passkeys_data_source.dart | 12 +++++--- .../deriv_passkeys_repository.dart | 29 +++++++++++++------ .../base_deriv_passkeys_repository.dart | 10 +++++-- .../services/deriv_passkeys_service.dart | 13 ++++++--- .../states/bloc/deriv_passkeys_bloc.dart | 9 ++++-- .../states/bloc/deriv_passkeys_event.dart | 5 +++- 7 files changed, 58 insertions(+), 26 deletions(-) diff --git a/packages/deriv_passkeys/lib/src/data/data_sources/base_deriv_passkeys_data_source.dart b/packages/deriv_passkeys/lib/src/data/data_sources/base_deriv_passkeys_data_source.dart index b1d63b90e..80ba174cd 100644 --- a/packages/deriv_passkeys/lib/src/data/data_sources/base_deriv_passkeys_data_source.dart +++ b/packages/deriv_passkeys/lib/src/data/data_sources/base_deriv_passkeys_data_source.dart @@ -35,12 +35,14 @@ abstract class BaseDerivPasskeysDataSource { }); /// Get options for registration with DerivPasskeys. - Future getRegisterOptions(); + Future getRegisterOptions({ + String? loginId, + }); /// Register credentials with DerivPasskeys. Future registerCredentials( PasskeysRegisterRequest request); /// Get passkeys list. - Future> getPasskeysList(); + Future> getPasskeysList({String? loginId}); } diff --git a/packages/deriv_passkeys/lib/src/data/data_sources/deriv_passkeys_data_source.dart b/packages/deriv_passkeys/lib/src/data/data_sources/deriv_passkeys_data_source.dart index 45d1950a2..4711f7e01 100644 --- a/packages/deriv_passkeys/lib/src/data/data_sources/deriv_passkeys_data_source.dart +++ b/packages/deriv_passkeys/lib/src/data/data_sources/deriv_passkeys_data_source.dart @@ -96,11 +96,14 @@ class DerivPasskeysDataSource extends BaseDerivPasskeysDataSource { } @override - Future getRegisterOptions() async { + Future getRegisterOptions({ + String? loginId, + }) async { try { final PasskeysRegisterOptionsReceive response = await PasskeysRegisterOptionsResponseExtended.fetchRaw( - const PasskeysRegisterOptionsRequest()); + PasskeysRegisterOptionsRequest(loginid: loginId), + ); if (response.passkeysRegisterOptions == null) { throw Exception('Failed to load register options!'); @@ -138,11 +141,12 @@ class DerivPasskeysDataSource extends BaseDerivPasskeysDataSource { } @override - Future> getPasskeysList() async { + Future> getPasskeysList({String? loginId}) async { try { final PasskeysListReceive response = await PasskeysListResponseExtended.fetchRaw( - const PasskeysListRequest()); + PasskeysListRequest(loginid: loginId), + ); if (response.passkeysList == null) { throw Exception('Failed to load passkeys list!'); diff --git a/packages/deriv_passkeys/lib/src/data/repositories/deriv_passkeys_repository.dart b/packages/deriv_passkeys/lib/src/data/repositories/deriv_passkeys_repository.dart index 0e0a472a1..b563776db 100644 --- a/packages/deriv_passkeys/lib/src/data/repositories/deriv_passkeys_repository.dart +++ b/packages/deriv_passkeys/lib/src/data/repositories/deriv_passkeys_repository.dart @@ -52,20 +52,31 @@ final class DerivPasskeysRepository extends BaseDerivPasskeysRepository { dataSource.mapper.mapDerivPasskeysVerifyCredentialsResponseModel); @override - Future getRegisterOptions() => dataSource - .getRegisterOptions() - .then(dataSource.mapper.mapDerivPasskeysRegisterOptionsModel); + Future getRegisterOptions({ + String? loginId, + }) => + dataSource + .getRegisterOptions(loginId: loginId) + .then(dataSource.mapper.mapDerivPasskeysRegisterOptionsModel); @override Future registerCredentials( - DerivPasskeysRegisterCredentialsEntity entity) => + DerivPasskeysRegisterCredentialsEntity entity, { + String? loginId, + }) => dataSource - .registerCredentials(dataSource.mapper - .mapDerivPasskeysRegisterCredentialsEntity(entity)) + .registerCredentials( + dataSource.mapper + .mapDerivPasskeysRegisterCredentialsEntity(entity) + .copyWith( + loginid: loginId, + ), + ) .then(dataSource.mapper.mapDerivPasskeyModel); @override - Future> getPasskeysList() => - dataSource.getPasskeysList().then((List models) => - models.map(dataSource.mapper.mapDerivPasskeyModel).toList()); + Future> getPasskeysList({String? loginId}) => + dataSource.getPasskeysList(loginId: loginId).then( + (List models) => + models.map(dataSource.mapper.mapDerivPasskeyModel).toList()); } diff --git a/packages/deriv_passkeys/lib/src/domain/base_repositories/base_deriv_passkeys_repository.dart b/packages/deriv_passkeys/lib/src/domain/base_repositories/base_deriv_passkeys_repository.dart index 63a1f366b..b69cd1217 100644 --- a/packages/deriv_passkeys/lib/src/domain/base_repositories/base_deriv_passkeys_repository.dart +++ b/packages/deriv_passkeys/lib/src/domain/base_repositories/base_deriv_passkeys_repository.dart @@ -24,12 +24,16 @@ abstract base class BaseDerivPasskeysRepository { }); /// Get options for registration with DerivPasskeys. - Future getRegisterOptions(); + Future getRegisterOptions({ + String? loginId, + }); /// Register credentials with DerivPasskeys. Future registerCredentials( - DerivPasskeysRegisterCredentialsEntity entity); + DerivPasskeysRegisterCredentialsEntity entity, { + String? loginId, + }); /// Get passkeys list. - Future> getPasskeysList(); + Future> getPasskeysList({String? loginId}); } diff --git a/packages/deriv_passkeys/lib/src/interactor/services/deriv_passkeys_service.dart b/packages/deriv_passkeys/lib/src/interactor/services/deriv_passkeys_service.dart index ec4809fc6..3086d6a30 100644 --- a/packages/deriv_passkeys/lib/src/interactor/services/deriv_passkeys_service.dart +++ b/packages/deriv_passkeys/lib/src/interactor/services/deriv_passkeys_service.dart @@ -25,9 +25,11 @@ class DerivPasskeysService { } /// Creates a passkey credential. - Future createCredential() async { + Future createCredential({ + String? loginId, + }) async { final Map getRegisterOptionsResult = - (await repository.getRegisterOptions()).options; + (await repository.getRegisterOptions(loginId: loginId)).options; final Map publicKeyCredentialUserEntityJson = { 'id': _base64UrlEncodeString( @@ -54,14 +56,17 @@ class DerivPasskeysService { publicKeyCredential: decodedCredentials, name: 'Passkey', ), + loginId: loginId, ); return getRegisterPasskeysResult; } /// Gets a list of passkeys. - Future> getPasskeysList() async { + Future> getPasskeysList({ + String? loginId, + }) async { final List getPasskeysListResult = - await repository.getPasskeysList(); + await repository.getPasskeysList(loginId: loginId); return getPasskeysListResult; } 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 247564dce..3280f06d3 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 @@ -88,7 +88,7 @@ class DerivPasskeysBloc extends Bloc { } emit(DerivPasskeysLoadingState()); await derivPasskeysService - .createCredential() + .createCredential(loginId: loginId) .then((DerivPasskeyEntity credential) async { emit(DerivPasskeysCreatedSuccessfullyState()); final DerivPasskeyEntity derivPasskeyEntity = credential; @@ -113,9 +113,9 @@ class DerivPasskeysBloc extends Bloc { (DerivPasskeysGetPasskeysListEvent event, Emitter emit) async { emit(DerivPasskeysLoadingState()); - + loginId = event.loginId; await derivPasskeysService - .getPasskeysList() + .getPasskeysList(loginId: loginId) .then((List _passkeysList) { passkeysList = _passkeysList; emit(DerivPasskeysLoadedState(passkeysList)); @@ -158,6 +158,9 @@ class DerivPasskeysBloc extends Bloc { ); } + /// Default account loginId used for multi-token authorization + String? loginId; + /// Passkeys connection info entity. final PasskeysConnectionInfoEntity connectionInfo; diff --git a/packages/deriv_passkeys/lib/src/presentation/states/bloc/deriv_passkeys_event.dart b/packages/deriv_passkeys/lib/src/presentation/states/bloc/deriv_passkeys_event.dart index ea2a56fbf..1756f8388 100644 --- a/packages/deriv_passkeys/lib/src/presentation/states/bloc/deriv_passkeys_event.dart +++ b/packages/deriv_passkeys/lib/src/presentation/states/bloc/deriv_passkeys_event.dart @@ -18,7 +18,10 @@ class DerivPasskeysVerifyCredentialEvent extends DerivPasskeysEvent {} /// [DerivPasskeysGetPasskeysListEvent] represents the get passkeys list event within the DerivPasskeys flow. class DerivPasskeysGetPasskeysListEvent extends DerivPasskeysEvent { /// Creates a [DerivPasskeysGetPasskeysListEvent]. - const DerivPasskeysGetPasskeysListEvent(); + const DerivPasskeysGetPasskeysListEvent({this.loginId}); + + /// Default account loginId used for multi-token authorization + final String? loginId; @override List get props => [];