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