TF-605 Use bearer token download attachment on iOS
This commit is contained in:
@@ -194,11 +194,17 @@ class EmailAPI {
|
||||
AccountRequest accountRequest,
|
||||
CancelToken cancelToken
|
||||
) async {
|
||||
final authentication = accountRequest.authenticationType == AuthenticationType.oidc
|
||||
? accountRequest.bearerToken
|
||||
: accountRequest.basicAuth;
|
||||
|
||||
log('EmailAPI::exportAttachment(): authentication: $authentication');
|
||||
|
||||
return _downloadManager.downloadFile(
|
||||
attachment.getDownloadUrl(baseDownloadUrl, accountId),
|
||||
getTemporaryDirectory(),
|
||||
attachment.name ?? '',
|
||||
accountRequest.basicAuth,
|
||||
authentication,
|
||||
cancelToken: cancelToken);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,10 @@ class DownloadAttachmentForWebInteractor {
|
||||
[credentialRepository.getUserName(), credentialRepository.getPassword()],
|
||||
eagerError: true
|
||||
).then((List responses) async {
|
||||
final accountRequest = AccountRequest(responses.first, responses.last);
|
||||
final accountRequest = AccountRequest(
|
||||
userName: responses.first,
|
||||
password: responses.last,
|
||||
authenticationType: AuthenticationType.basic);
|
||||
return await emailRepository.downloadAttachmentForWeb(
|
||||
attachment,
|
||||
accountId,
|
||||
|
||||
@@ -22,7 +22,10 @@ class DownloadAttachmentsInteractor {
|
||||
[credentialRepository.getUserName(), credentialRepository.getPassword()],
|
||||
eagerError: true
|
||||
).then((List responses) async {
|
||||
final accountRequest = AccountRequest(responses.first, responses.last);
|
||||
final accountRequest = AccountRequest(
|
||||
userName: responses.first,
|
||||
password: responses.last,
|
||||
authenticationType: AuthenticationType.basic);
|
||||
return await emailRepository.downloadAttachments(
|
||||
attachments,
|
||||
accountId,
|
||||
|
||||
@@ -7,13 +7,22 @@ import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:model/model.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/repository/email_repository.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/export_attachment_state.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/repository/credential_repository.dart';
|
||||
|
||||
class ExportAttachmentInteractor {
|
||||
final EmailRepository emailRepository;
|
||||
final CredentialRepository credentialRepository;
|
||||
final AccountRepository _accountRepository;
|
||||
final AuthenticationOIDCRepository _authenticationOIDCRepository;
|
||||
|
||||
ExportAttachmentInteractor(this.emailRepository, this.credentialRepository);
|
||||
ExportAttachmentInteractor(
|
||||
this.emailRepository,
|
||||
this.credentialRepository,
|
||||
this._accountRepository,
|
||||
this._authenticationOIDCRepository,
|
||||
);
|
||||
|
||||
Stream<Either<Failure, Success>> execute(
|
||||
Attachment attachment,
|
||||
@@ -22,11 +31,34 @@ class ExportAttachmentInteractor {
|
||||
CancelToken cancelToken
|
||||
) async* {
|
||||
try {
|
||||
final filePath = await Future.wait(
|
||||
[credentialRepository.getUserName(), credentialRepository.getPassword()],
|
||||
eagerError: true
|
||||
final account = await _accountRepository.getCurrentAccount();
|
||||
|
||||
log('ExportAttachmentInteractor::execute(): account: $account');
|
||||
|
||||
final filePath = await Future.wait([
|
||||
if (account.authenticationType == AuthenticationType.oidc)
|
||||
_authenticationOIDCRepository.getStoredTokenOIDC(account.id)
|
||||
else
|
||||
...[
|
||||
credentialRepository.getUserName(),
|
||||
credentialRepository.getPassword()
|
||||
]
|
||||
], eagerError: true
|
||||
).then((List responses) async {
|
||||
final accountRequest = AccountRequest(responses.first, responses.last);
|
||||
AccountRequest accountRequest;
|
||||
|
||||
if (account.authenticationType == AuthenticationType.oidc) {
|
||||
final tokenOidc = responses.first as TokenOIDC;
|
||||
accountRequest = AccountRequest(
|
||||
token: tokenOidc.toToken(),
|
||||
authenticationType: AuthenticationType.oidc);
|
||||
} else {
|
||||
accountRequest = AccountRequest(
|
||||
userName: responses.first as UserName,
|
||||
password: responses.last as Password,
|
||||
authenticationType: AuthenticationType.basic);
|
||||
}
|
||||
|
||||
return await emailRepository.exportAttachment(
|
||||
attachment,
|
||||
accountId,
|
||||
@@ -36,6 +68,7 @@ class ExportAttachmentInteractor {
|
||||
});
|
||||
yield Right<Failure, Success>(ExportAttachmentSuccess(filePath));
|
||||
} catch (exception) {
|
||||
log('ExportAttachmentInteractor::execute(): exception: $exception');
|
||||
yield Left<Failure, Success>(ExportAttachmentFailure(exception));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,19 @@ import 'package:tmail_ui_user/features/email/domain/usecases/mark_as_email_read_
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/move_to_mailbox_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/mark_as_star_email_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/email_controller.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/datasource/account_datasource.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/datasource/authentication_oidc_datasource.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/datasource_impl/authentication_oidc_datasource_impl.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/datasource_impl/hive_account_datasource_impl.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/local/account_cache_manager.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/local/oidc_configuration_cache_manager.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/local/token_oidc_cache_manager.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/network/oidc_http_client.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/repository/account_repository_impl.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/repository/authentication_oidc_repository_impl.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/repository/credential_repository_impl.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/repository/credential_repository.dart';
|
||||
|
||||
class EmailBindings extends BaseBindings {
|
||||
@@ -41,15 +53,23 @@ class EmailBindings extends BaseBindings {
|
||||
void bindingsDataSource() {
|
||||
Get.lazyPut<EmailDataSource>(() => Get.find<EmailDataSourceImpl>());
|
||||
Get.lazyPut<HtmlDataSource>(() => Get.find<HtmlDataSourceImpl>());
|
||||
Get.lazyPut<AccountDatasource>(() => Get.find<HiveAccountDatasourceImpl>());
|
||||
Get.lazyPut<AuthenticationOIDCDataSource>(() => Get.find<AuthenticationOIDCDataSourceImpl>());
|
||||
}
|
||||
|
||||
@override
|
||||
void bindingsDataSourceImpl() {
|
||||
Get.lazyPut(() => EmailDataSourceImpl(Get.find<EmailAPI>()));
|
||||
Get.lazyPut(() => HiveAccountDatasourceImpl(Get.find<AccountCacheManager>()));
|
||||
Get.lazyPut(() => HtmlDataSourceImpl(
|
||||
Get.find<HtmlAnalyzer>(),
|
||||
Get.find<DioClient>(),
|
||||
));
|
||||
Get.lazyPut(() => AuthenticationOIDCDataSourceImpl(
|
||||
Get.find<OIDCHttpClient>(),
|
||||
Get.find<TokenOidcCacheManager>(),
|
||||
Get.find<OidcConfigurationCacheManager>()
|
||||
));
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -63,6 +83,8 @@ class EmailBindings extends BaseBindings {
|
||||
Get.lazyPut(() => ExportAttachmentInteractor(
|
||||
Get.find<EmailRepository>(),
|
||||
Get.find<CredentialRepository>(),
|
||||
Get.find<AccountRepository>(),
|
||||
Get.find<AuthenticationOIDCRepository>(),
|
||||
));
|
||||
Get.lazyPut(() => MoveToMailboxInteractor(Get.find<EmailRepository>()));
|
||||
Get.lazyPut(() => MarkAsStarEmailInteractor(Get.find<EmailRepository>()));
|
||||
@@ -76,6 +98,8 @@ class EmailBindings extends BaseBindings {
|
||||
void bindingsRepository() {
|
||||
Get.lazyPut<EmailRepository>(() => Get.find<EmailRepositoryImpl>());
|
||||
Get.lazyPut<CredentialRepository>(() => Get.find<CredentialRepositoryImpl>());
|
||||
Get.lazyPut<AccountRepository>(() => Get.find<AccountRepositoryImpl>());
|
||||
Get.lazyPut<AuthenticationOIDCRepository>(() => Get.find<AuthenticationOIDCRepositoryImpl>());
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -85,5 +109,7 @@ class EmailBindings extends BaseBindings {
|
||||
Get.find<HtmlDataSource>(),
|
||||
));
|
||||
Get.lazyPut(() => CredentialRepositoryImpl(Get.find<SharedPreferences>()));
|
||||
Get.lazyPut(() => AccountRepositoryImpl(Get.find<AccountDatasource>()));
|
||||
Get.lazyPut(() => AuthenticationOIDCRepositoryImpl(Get.find<AuthenticationOIDCDataSource>()));
|
||||
}
|
||||
}
|
||||
@@ -155,6 +155,7 @@ class EmailController extends BaseController {
|
||||
|
||||
@override
|
||||
void onError(error) {
|
||||
log('EmailController::onError(): $error');
|
||||
}
|
||||
|
||||
void _getEmailContentSuccess(GetEmailContentSuccess success) {
|
||||
|
||||
@@ -12,6 +12,7 @@ class TokenOidcCacheManager {
|
||||
|
||||
Future<TokenOIDC> getTokenOidc(String tokenIdHash) async {
|
||||
final tokenCache = await _tokenOidcCacheClient.getItem(tokenIdHash);
|
||||
log('TokenOidcCacheManager::getTokenOidc(): tokenCache: $tokenCache');
|
||||
if (tokenCache == null) {
|
||||
throw NotFoundStoredTokenException();
|
||||
} else {
|
||||
|
||||
@@ -10,7 +10,7 @@ extension PresentationMailboxExtension on PresentationMailbox {
|
||||
return imagePaths.icMailboxInbox;
|
||||
case 'drafts':
|
||||
return imagePaths.icMailboxDrafts;
|
||||
case 'outbox':
|
||||
case 'archive':
|
||||
return imagePaths.icMailboxArchived;
|
||||
case 'sent':
|
||||
return imagePaths.icMailboxSent;
|
||||
|
||||
@@ -4,18 +4,23 @@ import 'package:equatable/equatable.dart';
|
||||
import 'package:model/model.dart';
|
||||
|
||||
class AccountRequest with EquatableMixin {
|
||||
final UserName userName;
|
||||
final Password password;
|
||||
final UserName? userName;
|
||||
final Password? password;
|
||||
final Token? token;
|
||||
final AuthenticationType authenticationType;
|
||||
|
||||
AccountRequest(this.userName, this.password);
|
||||
AccountRequest({
|
||||
this.userName,
|
||||
this.password,
|
||||
this.token,
|
||||
this.authenticationType = AuthenticationType.none,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() => <String, dynamic>{
|
||||
'username': userName.userName,
|
||||
'password': password.value,
|
||||
};
|
||||
String get basicAuth =>
|
||||
'Basic ${base64Encode(utf8.encode('${userName?.userName}:${password?.value}'))}';
|
||||
|
||||
String get basicAuth => 'Basic ${base64Encode(utf8.encode('${userName.userName}:${password.value}'))}';
|
||||
String get bearerToken => 'Bearer ${token?.token}';
|
||||
|
||||
@override
|
||||
List<Object> get props => [userName, password];
|
||||
List<Object?> get props => [userName, password];
|
||||
}
|
||||
Reference in New Issue
Block a user