TF-605 Use bearer token download attachment on iOS
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user