TF-1317 Update authentication account to store AccountId
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/id.dart';
|
||||
import 'package:model/account/account.dart';
|
||||
import 'package:model/account/authentication_type.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/model/account_cache.dart';
|
||||
@@ -15,6 +17,12 @@ extension AccountCacheExtension on AccountCache {
|
||||
|
||||
Account toAccount() {
|
||||
final authenticationType = fromAuthenticationTypeString();
|
||||
return Account(id, authenticationType, isSelected: isSelected);
|
||||
return Account(
|
||||
id,
|
||||
authenticationType,
|
||||
isSelected: isSelected,
|
||||
accountId: accountId != null ? AccountId(Id(accountId!)) : null,
|
||||
apiUrl: apiUrl
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,12 @@ import 'package:tmail_ui_user/features/login/data/model/account_cache.dart';
|
||||
|
||||
extension AccountExtensions on Account {
|
||||
AccountCache toCache() {
|
||||
return AccountCache(id, authenticationType.asString(), isSelected: isSelected);
|
||||
return AccountCache(
|
||||
id,
|
||||
authenticationType.asString(),
|
||||
isSelected: isSelected,
|
||||
accountId: accountId?.id.value,
|
||||
apiUrl: apiUrl
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -15,8 +15,28 @@ class AccountCache extends HiveObject with EquatableMixin {
|
||||
@HiveField(2)
|
||||
final bool isSelected;
|
||||
|
||||
AccountCache(this.id, this.authenticationType, {required this.isSelected});
|
||||
@HiveField(3)
|
||||
final String? accountId;
|
||||
|
||||
@HiveField(4)
|
||||
final String? apiUrl;
|
||||
|
||||
AccountCache(
|
||||
this.id,
|
||||
this.authenticationType,
|
||||
{
|
||||
required this.isSelected,
|
||||
this.accountId,
|
||||
this.apiUrl
|
||||
}
|
||||
);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [id, authenticationType, isSelected];
|
||||
List<Object?> get props => [
|
||||
id,
|
||||
authenticationType,
|
||||
isSelected,
|
||||
accountId,
|
||||
apiUrl
|
||||
];
|
||||
}
|
||||
@@ -88,13 +88,18 @@ class AuthorizationInterceptors extends InterceptorsWrapper {
|
||||
_configOIDC!.scopes,
|
||||
_token!.refreshToken);
|
||||
|
||||
final accountCurrent = await _accountCacheManager.getSelectedAccount();
|
||||
|
||||
await Future.wait([
|
||||
_tokenOidcCacheManager.persistOneTokenOidc(newToken),
|
||||
_accountCacheManager.deleteSelectedAccount(_token!.tokenIdHash),
|
||||
_accountCacheManager.setSelectedAccount(Account(
|
||||
newToken.tokenIdHash,
|
||||
AuthenticationType.oidc,
|
||||
isSelected: true)),
|
||||
newToken.tokenIdHash,
|
||||
AuthenticationType.oidc,
|
||||
isSelected: true,
|
||||
accountId: accountCurrent.accountId,
|
||||
apiUrl: accountCurrent.apiUrl
|
||||
)),
|
||||
]);
|
||||
|
||||
log('AuthorizationInterceptors::onError(): refreshToken: $newToken');
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
|
||||
class UpdateAuthenticationAccountLoading extends LoadingState {}
|
||||
|
||||
class UpdateAuthenticationAccountSuccess extends UIState {
|
||||
|
||||
UpdateAuthenticationAccountSuccess();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class UpdateAuthenticationAccountFailure extends FeatureFailure {
|
||||
final dynamic exception;
|
||||
|
||||
UpdateAuthenticationAccountFailure(this.exception);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [exception];
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
|
||||
import 'package:core/core.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:model/model.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/extensions/oidc_configuration_extensions.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/repository/account_repository.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/repository/authentication_oidc_repository.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/state/refresh_token_oidc_state.dart';
|
||||
|
||||
class RefreshTokenOIDCInteractor {
|
||||
|
||||
final AuthenticationOIDCRepository authenticationOIDCRepository;
|
||||
final AccountRepository _accountRepository;
|
||||
|
||||
RefreshTokenOIDCInteractor(this.authenticationOIDCRepository, this._accountRepository);
|
||||
|
||||
Future<Either<Failure, Success>> execute(
|
||||
OIDCConfiguration config,
|
||||
String refreshToken) async {
|
||||
try {
|
||||
final newTokenOIDC = await authenticationOIDCRepository.refreshingTokensOIDC(
|
||||
config.clientId,
|
||||
config.redirectUrl,
|
||||
config.discoveryUrl,
|
||||
config.scopes,
|
||||
refreshToken);
|
||||
|
||||
await Future.wait([
|
||||
_accountRepository.setCurrentAccount(Account(
|
||||
newTokenOIDC.tokenId.hashCode.toString(),
|
||||
AuthenticationType.oidc,
|
||||
isSelected: true)),
|
||||
authenticationOIDCRepository.persistTokenOIDC(newTokenOIDC),
|
||||
]);
|
||||
return Right<Failure, Success>(RefreshTokenOIDCSuccess(newTokenOIDC));
|
||||
} catch (e) {
|
||||
logError('RefreshTokenOIDCInteractor::execute(): $e');
|
||||
return Left<Failure, Success>(RefreshTokenOIDCFailure(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:model/extensions/account_extension.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/repository/account_repository.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/state/update_authentication_account_state.dart';
|
||||
|
||||
class UpdateAuthenticationAccountInteractor {
|
||||
final AccountRepository _accountRepository;
|
||||
|
||||
UpdateAuthenticationAccountInteractor(this._accountRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute(AccountId accountId, String apiUrl) async* {
|
||||
try{
|
||||
yield Right(UpdateAuthenticationAccountLoading());
|
||||
final currentAccount = await _accountRepository.getCurrentAccount();
|
||||
await _accountRepository.setCurrentAccount(currentAccount.fromAccountId(
|
||||
accountId: accountId,
|
||||
apiUrl: apiUrl
|
||||
));
|
||||
yield Right(UpdateAuthenticationAccountSuccess());
|
||||
} catch(e) {
|
||||
yield Left(UpdateAuthenticationAccountFailure(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,6 +46,7 @@ import 'package:tmail_ui_user/features/login/domain/usecases/get_stored_token_oi
|
||||
import 'package:tmail_ui_user/features/login/domain/usecases/get_token_oidc_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/usecases/save_login_url_on_mobile_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/usecases/save_login_username_on_mobile_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/usecases/update_authentication_account_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/login/presentation/login_controller.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/usecases/log_out_oidc_interactor.dart';
|
||||
import 'package:tmail_ui_user/main/bindings/network/binding_tag.dart';
|
||||
@@ -60,6 +61,7 @@ class LoginBindings extends BaseBindings {
|
||||
Get.find<LogoutOidcInteractor>(),
|
||||
Get.find<DeleteAuthorityOidcInteractor>(),
|
||||
Get.find<GetAuthenticatedAccountInteractor>(),
|
||||
Get.find<UpdateAuthenticationAccountInteractor>(),
|
||||
Get.find<AuthenticationInteractor>(),
|
||||
Get.find<DynamicUrlInterceptors>(),
|
||||
Get.find<AuthorizationInterceptors>(),
|
||||
@@ -166,6 +168,7 @@ class LoginBindings extends BaseBindings {
|
||||
Get.lazyPut(() => GetAllRecentLoginUsernameOnMobileInteractor(
|
||||
Get.find<LoginUsernameRepository>()
|
||||
));
|
||||
Get.lazyPut(() => UpdateAuthenticationAccountInteractor(Get.find<AccountRepository>()));
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -43,6 +43,7 @@ import 'package:tmail_ui_user/features/login/domain/usecases/get_stored_oidc_con
|
||||
import 'package:tmail_ui_user/features/login/domain/usecases/get_token_oidc_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/usecases/save_login_url_on_mobile_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/usecases/save_login_username_on_mobile_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/usecases/update_authentication_account_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/login/presentation/login_form_type.dart';
|
||||
import 'package:tmail_ui_user/features/login/presentation/model/login_arguments.dart';
|
||||
import 'package:tmail_ui_user/features/login/presentation/state/login_state.dart';
|
||||
@@ -81,6 +82,7 @@ class LoginController extends ReloadableController {
|
||||
LogoutOidcInteractor logoutOidcInteractor,
|
||||
DeleteAuthorityOidcInteractor deleteAuthorityOidcInteractor,
|
||||
GetAuthenticatedAccountInteractor getAuthenticatedAccountInteractor,
|
||||
UpdateAuthenticationAccountInteractor updateAuthenticationAccountInteractor,
|
||||
this._authenticationInteractor,
|
||||
this._dynamicUrlInterceptors,
|
||||
this._authorizationInterceptors,
|
||||
@@ -96,9 +98,12 @@ class LoginController extends ReloadableController {
|
||||
this._getAllRecentLoginUrlOnMobileInteractor,
|
||||
this._saveLoginUsernameOnMobileInteractor,
|
||||
this._getAllRecentLoginUsernameOnMobileInteractor,
|
||||
) : super(logoutOidcInteractor,
|
||||
deleteAuthorityOidcInteractor,
|
||||
getAuthenticatedAccountInteractor);
|
||||
) : super(
|
||||
logoutOidcInteractor,
|
||||
deleteAuthorityOidcInteractor,
|
||||
getAuthenticatedAccountInteractor,
|
||||
updateAuthenticationAccountInteractor
|
||||
);
|
||||
|
||||
var loginState = LoginState(Right(LoginInitAction())).obs;
|
||||
final loginFormType = LoginFormType.baseUrlForm.obs;
|
||||
|
||||
Reference in New Issue
Block a user