TF-3278 Handle open app via deep link at MailboxDashboard screen
This commit is contained in:
@@ -15,6 +15,6 @@ class DeepLinkBindings extends Bindings {
|
||||
Get.find<AccountRepository>(),
|
||||
Get.find<CredentialRepository>(),
|
||||
));
|
||||
Get.put(DeepLinksManager(Get.find<AutoSignInViaDeepLinkInteractor>()));
|
||||
Get.put(DeepLinksManager());
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import 'package:tmail_ui_user/features/caching/clients/firebase_registration_cac
|
||||
import 'package:tmail_ui_user/features/caching/clients/hive_cache_version_client.dart';
|
||||
import 'package:tmail_ui_user/features/caching/clients/mailbox_cache_client.dart';
|
||||
import 'package:tmail_ui_user/features/caching/clients/new_email_hive_cache_client.dart';
|
||||
import 'package:tmail_ui_user/features/caching/clients/oidc_configuration_cache_client.dart';
|
||||
import 'package:tmail_ui_user/features/caching/clients/opened_email_hive_cache_client.dart';
|
||||
import 'package:tmail_ui_user/features/caching/clients/recent_login_url_cache_client.dart';
|
||||
import 'package:tmail_ui_user/features/caching/clients/recent_login_username_cache_client.dart';
|
||||
@@ -70,7 +71,8 @@ class LocalBindings extends Bindings {
|
||||
Get.put(EncryptionKeyCacheManager(Get.find<EncryptionKeyCacheClient>()));
|
||||
Get.put(AuthenticationInfoCacheClient());
|
||||
Get.put(AuthenticationInfoCacheManager(Get.find<AuthenticationInfoCacheClient>()));
|
||||
Get.put(OidcConfigurationCacheManager(Get.find<SharedPreferences>()));
|
||||
Get.put(OidcConfigurationCacheClient());
|
||||
Get.put(OidcConfigurationCacheManager(Get.find<SharedPreferences>(), Get.find<OidcConfigurationCacheClient>()));
|
||||
Get.put(LanguageCacheManager(Get.find<SharedPreferences>()));
|
||||
Get.put(RecentLoginUrlCacheClient());
|
||||
Get.put(RecentLoginUrlCacheManager((Get.find<RecentLoginUrlCacheClient>())));
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
|
||||
import 'package:tmail_ui_user/features/home/domain/state/auto_sign_in_via_deep_link_state.dart';
|
||||
import 'package:tmail_ui_user/main/deep_links/deep_link_data.dart';
|
||||
|
||||
typedef OnDeepLinkSuccessCallback = Function(AutoSignInViaDeepLinkSuccess success);
|
||||
|
||||
typedef OnDeepLinkFailureCallback = Function();
|
||||
|
||||
typedef OnDeepLinkConfirmLogoutCallback = Function(DeepLinkData deepLinkData);
|
||||
@@ -0,0 +1,5 @@
|
||||
|
||||
enum DeepLinkActionType {
|
||||
openApp,
|
||||
unknown;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
|
||||
import 'package:tmail_ui_user/features/home/domain/state/auto_sign_in_via_deep_link_state.dart';
|
||||
import 'package:tmail_ui_user/main/deep_links/deep_link_data.dart';
|
||||
|
||||
typedef OnAutoSignInViaDeepLinkSuccessCallback = Function(AutoSignInViaDeepLinkSuccess success);
|
||||
|
||||
typedef OnDeepLinkSuccessCallback = Function(DeepLinkData deepLinkData);
|
||||
|
||||
typedef OnDeepLinkFailureCallback = Function();
|
||||
|
||||
typedef OnDeepLinkConfirmLogoutCallback<T> = Function(T t);
|
||||
@@ -1,45 +1,11 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:model/model.dart';
|
||||
import 'package:tmail_ui_user/main/deep_links/deep_link_action_type.dart';
|
||||
|
||||
class DeepLinkData with EquatableMixin {
|
||||
final String action;
|
||||
final String? accessToken;
|
||||
final String? refreshToken;
|
||||
final String? idToken;
|
||||
final int? expiresIn;
|
||||
final String? username;
|
||||
final DeepLinkActionType actionType;
|
||||
|
||||
DeepLinkData({
|
||||
required this.action,
|
||||
this.accessToken,
|
||||
this.refreshToken,
|
||||
this.idToken,
|
||||
this.expiresIn,
|
||||
this.username,
|
||||
});
|
||||
|
||||
bool isValidToken() => accessToken?.isNotEmpty == true && username?.isNotEmpty == true;
|
||||
|
||||
TokenOIDC getTokenOIDC() {
|
||||
final expiredTime = expiresIn == null
|
||||
? null
|
||||
: DateTime.now().add(Duration(seconds: expiresIn!));
|
||||
|
||||
return TokenOIDC(
|
||||
accessToken!,
|
||||
TokenId(idToken ?? ''),
|
||||
refreshToken ?? '',
|
||||
expiredTime: expiredTime,
|
||||
);
|
||||
}
|
||||
DeepLinkData({required this.actionType});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
action,
|
||||
accessToken,
|
||||
refreshToken,
|
||||
idToken,
|
||||
expiresIn,
|
||||
username,
|
||||
];
|
||||
List<Object?> get props => [actionType];
|
||||
}
|
||||
|
||||
@@ -1,24 +1,15 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:app_links/app_links.dart';
|
||||
import 'package:core/presentation/extensions/color_extension.dart';
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:model/oidc/oidc_configuration.dart';
|
||||
import 'package:rxdart/subjects.dart';
|
||||
import 'package:tmail_ui_user/features/base/mixin/message_dialog_action_mixin.dart';
|
||||
import 'package:tmail_ui_user/features/home/domain/state/auto_sign_in_via_deep_link_state.dart';
|
||||
import 'package:tmail_ui_user/features/home/domain/usecases/auto_sign_in_via_deep_link_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/network/config/oidc_constant.dart';
|
||||
import 'package:tmail_ui_user/main/deep_links/deep_link_action_define.dart';
|
||||
import 'package:tmail_ui_user/main/deep_links/deep_link_action_type.dart';
|
||||
import 'package:tmail_ui_user/main/deep_links/deep_link_callback_action_define.dart';
|
||||
import 'package:tmail_ui_user/main/deep_links/deep_link_data.dart';
|
||||
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
|
||||
import 'package:tmail_ui_user/main/routes/route_navigation.dart';
|
||||
import 'package:tmail_ui_user/main/utils/app_config.dart';
|
||||
import 'package:tmail_ui_user/main/deep_links/open_app_deep_link_handler_mixin.dart';
|
||||
|
||||
class DeepLinksManager with MessageDialogActionMixin {
|
||||
|
||||
final AutoSignInViaDeepLinkInteractor _autoSignInViaDeepLinkInteractor;
|
||||
class DeepLinksManager with MessageDialogActionMixin, OpenAppDeepLinkHandlerMixin {
|
||||
|
||||
BehaviorSubject<DeepLinkData?> _pendingDeepLinkData = BehaviorSubject.seeded(null);
|
||||
|
||||
@@ -26,8 +17,6 @@ class DeepLinksManager with MessageDialogActionMixin {
|
||||
|
||||
StreamSubscription<Uri>? _deepLinkStreamSubscription;
|
||||
|
||||
DeepLinksManager(this._autoSignInViaDeepLinkInteractor);
|
||||
|
||||
Future<DeepLinkData?> getDeepLinkData() async {
|
||||
final uriLink = await AppLinks().getInitialLink();
|
||||
log('DeepLinksManager::getDeepLinkData:uriLink = $uriLink');
|
||||
@@ -63,194 +52,47 @@ class DeepLinksManager with MessageDialogActionMixin {
|
||||
|
||||
DeepLinkData? parseDeepLink(String url) {
|
||||
try {
|
||||
final updatedUrl = url.replaceFirst(
|
||||
OIDCConstant.twakeWorkplaceUrlScheme,
|
||||
'https',
|
||||
);
|
||||
final uri = Uri.parse(updatedUrl);
|
||||
final decodedUrl = Uri.decodeFull(url);
|
||||
final uri = Uri.parse(decodedUrl);
|
||||
log('DeepLinksManager::parseDeepLink:uri = $uri');
|
||||
final action = uri.host;
|
||||
final accessToken = uri.queryParameters['access_token'];
|
||||
final refreshToken = uri.queryParameters['refresh_token'];
|
||||
final idToken = uri.queryParameters['id_token'];
|
||||
final expiresInStr = uri.queryParameters['expires_in'];
|
||||
final username = uri.queryParameters['username'];
|
||||
|
||||
final expiresIn = expiresInStr != null
|
||||
? int.tryParse(expiresInStr)
|
||||
: null;
|
||||
|
||||
return DeepLinkData(
|
||||
action: action,
|
||||
accessToken: accessToken,
|
||||
refreshToken: refreshToken,
|
||||
idToken: idToken,
|
||||
expiresIn: expiresIn,
|
||||
username: username,
|
||||
);
|
||||
if (action == DeepLinkActionType.openApp.name.toLowerCase()) {
|
||||
return parseOpenAppDeepLink(uri);
|
||||
} else {
|
||||
return DeepLinkData(actionType: DeepLinkActionType.unknown);
|
||||
}
|
||||
} catch (e) {
|
||||
logError('DeepLinksManager::parseDeepLink:Exception = $e');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> handleDeepLinksWhenAppOnForegroundNotSignedIn({
|
||||
required DeepLinkData deepLinkData,
|
||||
required OnDeepLinkSuccessCallback onSuccessCallback,
|
||||
OnDeepLinkFailureCallback? onFailureCallback,
|
||||
}) async {
|
||||
log('DeepLinksManager::handleDeepLinksWhenAppOnForegroundNotSignedIn:DeepLinkData = $deepLinkData');
|
||||
if (deepLinkData.action.toLowerCase() == AppConfig.openAppHostDeepLink.toLowerCase()) {
|
||||
_handleOpenApp(
|
||||
deepLinkData: deepLinkData,
|
||||
onFailureCallback: onFailureCallback,
|
||||
onSuccessCallback: onSuccessCallback,
|
||||
);
|
||||
} else {
|
||||
onFailureCallback?.call();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> handleDeepLinksWhenAppTerminatedNotSignedIn({
|
||||
Future<void> handleDeepLinksWhenAppTerminated({
|
||||
required OnDeepLinkSuccessCallback onSuccessCallback,
|
||||
required OnDeepLinkFailureCallback onFailureCallback,
|
||||
}) async {
|
||||
final deepLinkData = await getDeepLinkData();
|
||||
log('DeepLinksManager::handleDeepLinksWhenAppTerminatedNotSignedIn:DeepLinkData = $deepLinkData');
|
||||
|
||||
if (deepLinkData == null) {
|
||||
onFailureCallback();
|
||||
return;
|
||||
}
|
||||
|
||||
if (deepLinkData.action.toLowerCase() == AppConfig.openAppHostDeepLink.toLowerCase()) {
|
||||
_handleOpenApp(
|
||||
deepLinkData: deepLinkData,
|
||||
onFailureCallback: onFailureCallback,
|
||||
onSuccessCallback: onSuccessCallback,
|
||||
);
|
||||
} else {
|
||||
onFailureCallback();
|
||||
}
|
||||
onSuccessCallback(deepLinkData);
|
||||
}
|
||||
|
||||
Future<void> handleDeepLinksWhenAppTerminatedSignedIn({
|
||||
required String? username,
|
||||
required OnDeepLinkConfirmLogoutCallback onConfirmCallback,
|
||||
required OnDeepLinkFailureCallback onFailureCallback,
|
||||
Future<void> handleDeepLinksWhenAppRunning({
|
||||
required DeepLinkData? deepLinkData,
|
||||
required OnDeepLinkSuccessCallback onSuccessCallback,
|
||||
OnDeepLinkFailureCallback? onFailureCallback,
|
||||
}) async {
|
||||
final deepLinkData = await getDeepLinkData();
|
||||
log('DeepLinksManager::handleDeepLinksWhenAppTerminatedSignedIn:DeepLinkData = $deepLinkData');
|
||||
if (deepLinkData == null) {
|
||||
onFailureCallback();
|
||||
onFailureCallback?.call();
|
||||
return;
|
||||
}
|
||||
|
||||
if (deepLinkData.action.toLowerCase() == AppConfig.openAppHostDeepLink.toLowerCase()) {
|
||||
if (deepLinkData.username?.isNotEmpty != true || username?.isNotEmpty != true) {
|
||||
onFailureCallback();
|
||||
return;
|
||||
}
|
||||
|
||||
if (deepLinkData.username == username || currentContext == null) {
|
||||
onFailureCallback();
|
||||
} else {
|
||||
_showConfirmDialogSwitchAccount(
|
||||
context: currentContext!,
|
||||
username: username!,
|
||||
onConfirmAction: () => onConfirmCallback(deepLinkData),
|
||||
onCancelAction: onFailureCallback,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
onFailureCallback();
|
||||
}
|
||||
}
|
||||
|
||||
void _handleOpenApp({
|
||||
required DeepLinkData deepLinkData,
|
||||
required OnDeepLinkSuccessCallback onSuccessCallback,
|
||||
OnDeepLinkFailureCallback? onFailureCallback,
|
||||
}) {
|
||||
autoSignInViaDeepLink(
|
||||
deepLinkData: deepLinkData,
|
||||
onFailureCallback: onFailureCallback,
|
||||
onSuccessCallback: onSuccessCallback,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> autoSignInViaDeepLink({
|
||||
required DeepLinkData deepLinkData,
|
||||
required OnDeepLinkSuccessCallback onSuccessCallback,
|
||||
OnDeepLinkFailureCallback? onFailureCallback,
|
||||
}) async {
|
||||
try {
|
||||
if (deepLinkData.isValidToken()) {
|
||||
final autoSignInViewState = await _autoSignInViaDeepLinkInteractor.execute(
|
||||
baseUri: Uri.parse(AppConfig.saasJmapServerUrl),
|
||||
tokenOIDC: deepLinkData.getTokenOIDC(),
|
||||
oidcConfiguration: OIDCConfiguration(
|
||||
authority: AppConfig.saasRegistrationUrl,
|
||||
clientId: OIDCConstant.clientId,
|
||||
scopes: AppConfig.oidcScopes,
|
||||
),
|
||||
).last;
|
||||
|
||||
autoSignInViewState.fold(
|
||||
(failure) => onFailureCallback?.call(),
|
||||
(success) {
|
||||
if (success is AutoSignInViaDeepLinkSuccess) {
|
||||
onSuccessCallback(success);
|
||||
} else {
|
||||
onFailureCallback?.call();
|
||||
}
|
||||
},
|
||||
);
|
||||
} else {
|
||||
onFailureCallback?.call();
|
||||
}
|
||||
} catch (e) {
|
||||
logError('DeepLinksManager::_autoSignInViaDeepLink:Exception = $e');
|
||||
onFailureCallback?.call();
|
||||
}
|
||||
}
|
||||
|
||||
void _showConfirmDialogSwitchAccount({
|
||||
required BuildContext context,
|
||||
required String username,
|
||||
required Function onConfirmAction,
|
||||
required Function onCancelAction,
|
||||
}) {
|
||||
final appLocalizations = AppLocalizations.of(context);
|
||||
|
||||
showConfirmDialogAction(
|
||||
context,
|
||||
'',
|
||||
appLocalizations.yesLogout,
|
||||
title: appLocalizations.logoutConfirmation,
|
||||
alignCenter: true,
|
||||
outsideDismissible: false,
|
||||
titleActionButtonMaxLines: 1,
|
||||
titlePadding: const EdgeInsetsDirectional.only(start: 24, top: 24, end: 24, bottom: 12),
|
||||
messageStyle: const TextStyle(
|
||||
color: AppColor.colorTextBody,
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w400,
|
||||
),
|
||||
listTextSpan: [
|
||||
TextSpan(text: appLocalizations.messageConfirmationLogout),
|
||||
TextSpan(
|
||||
text: ' $username',
|
||||
style: const TextStyle(
|
||||
color: AppColor.colorTextBody,
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const TextSpan(text: ' ?'),
|
||||
],
|
||||
onConfirmAction: onConfirmAction,
|
||||
onCancelAction: onCancelAction,
|
||||
);
|
||||
onSuccessCallback(deepLinkData);
|
||||
}
|
||||
|
||||
void dispose() {
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
import 'package:model/oidc/oidc_configuration.dart';
|
||||
import 'package:model/oidc/token_id.dart';
|
||||
import 'package:model/oidc/token_oidc.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/network/config/oidc_constant.dart';
|
||||
import 'package:tmail_ui_user/main/deep_links/deep_link_action_type.dart';
|
||||
import 'package:tmail_ui_user/main/deep_links/deep_link_data.dart';
|
||||
import 'package:tmail_ui_user/main/utils/app_config.dart';
|
||||
|
||||
class OpenAppDeepLinkData extends DeepLinkData {
|
||||
final String registrationUrl;
|
||||
final String jmapUrl;
|
||||
final String username;
|
||||
final String accessToken;
|
||||
final String? refreshToken;
|
||||
final String? idToken;
|
||||
final int? expiresIn;
|
||||
|
||||
OpenAppDeepLinkData({
|
||||
super.actionType = DeepLinkActionType.openApp,
|
||||
required this.registrationUrl,
|
||||
required this.jmapUrl,
|
||||
required this.username,
|
||||
required this.accessToken,
|
||||
this.refreshToken,
|
||||
this.idToken,
|
||||
this.expiresIn,
|
||||
});
|
||||
|
||||
bool isValidAuthentication() =>
|
||||
accessToken.isNotEmpty &&
|
||||
username.isNotEmpty &&
|
||||
registrationUrl.isNotEmpty &&
|
||||
jmapUrl.isNotEmpty;
|
||||
|
||||
DateTime? _getExpiredTime() {
|
||||
return expiresIn != null
|
||||
? DateTime.now().add(Duration(seconds: expiresIn!))
|
||||
: null;
|
||||
}
|
||||
|
||||
bool isLoggedInWith(String currentUsername) => username == currentUsername;
|
||||
|
||||
TokenOIDC get tokenOIDC {
|
||||
return TokenOIDC(
|
||||
accessToken,
|
||||
TokenId(idToken ?? ''),
|
||||
refreshToken ?? '',
|
||||
expiredTime: _getExpiredTime(),
|
||||
);
|
||||
}
|
||||
|
||||
Uri get baseUri => Uri.parse(jmapUrl);
|
||||
|
||||
OIDCConfiguration get oidcConfiguration => OIDCConfiguration(
|
||||
authority: registrationUrl,
|
||||
clientId: OIDCConstant.clientId,
|
||||
scopes: AppConfig.oidcScopes,
|
||||
isTWP: true,
|
||||
);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
...super.props,
|
||||
registrationUrl,
|
||||
jmapUrl,
|
||||
username,
|
||||
accessToken,
|
||||
refreshToken,
|
||||
idToken,
|
||||
expiresIn,
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
import 'package:core/presentation/extensions/color_extension.dart';
|
||||
import 'package:core/presentation/extensions/either_view_state_extension.dart';
|
||||
import 'package:core/utils/string_convert.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:rich_text_composer/views/commons/logger.dart';
|
||||
import 'package:tmail_ui_user/features/base/mixin/message_dialog_action_mixin.dart';
|
||||
import 'package:tmail_ui_user/features/home/domain/state/auto_sign_in_via_deep_link_state.dart';
|
||||
import 'package:tmail_ui_user/features/home/domain/usecases/auto_sign_in_via_deep_link_interactor.dart';
|
||||
import 'package:tmail_ui_user/main/deep_links/deep_link_callback_action_define.dart';
|
||||
import 'package:tmail_ui_user/main/deep_links/open_app_deep_link_data.dart';
|
||||
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
|
||||
import 'package:tmail_ui_user/main/routes/route_navigation.dart';
|
||||
|
||||
mixin OpenAppDeepLinkHandlerMixin on MessageDialogActionMixin {
|
||||
OpenAppDeepLinkData? parseOpenAppDeepLink(Uri uri) {
|
||||
try {
|
||||
final accessToken = uri.queryParameters['access_token'] ?? '';
|
||||
final refreshToken = uri.queryParameters['refresh_token'];
|
||||
final idToken = uri.queryParameters['id_token'];
|
||||
final expiresInStr = uri.queryParameters['expires_in'];
|
||||
final username = uri.queryParameters['username'];
|
||||
final registrationUrl = uri.queryParameters['registrationUrl'] ?? '';
|
||||
final jmapUrl = uri.queryParameters['jmapUrl'] ?? '';
|
||||
|
||||
final expiresIn = expiresInStr != null
|
||||
? int.tryParse(expiresInStr)
|
||||
: null;
|
||||
|
||||
final usernameDecoded = username?.isNotEmpty == true
|
||||
? StringConvert.decodeBase64ToString(username!)
|
||||
: username ?? '';
|
||||
|
||||
return OpenAppDeepLinkData(
|
||||
registrationUrl: registrationUrl,
|
||||
jmapUrl: jmapUrl,
|
||||
accessToken: accessToken,
|
||||
refreshToken: refreshToken,
|
||||
idToken: idToken,
|
||||
expiresIn: expiresIn,
|
||||
username: usernameDecoded,
|
||||
);
|
||||
} catch (e) {
|
||||
logError('DeepLinksManager::parseOpenAppDeepLink:Exception = $e');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
void handleOpenAppDeepLinks({
|
||||
required OpenAppDeepLinkData openAppDeepLinkData,
|
||||
OnDeepLinkFailureCallback? onFailureCallback,
|
||||
OnAutoSignInViaDeepLinkSuccessCallback? onAutoSignInSuccessCallback,
|
||||
OnDeepLinkConfirmLogoutCallback<OpenAppDeepLinkData>? onConfirmLogoutCallback,
|
||||
UserName? username,
|
||||
bool isSignedIn = true,
|
||||
}) {
|
||||
if (!openAppDeepLinkData.isValidAuthentication()) {
|
||||
onFailureCallback?.call();
|
||||
return;
|
||||
}
|
||||
|
||||
if (isSignedIn) {
|
||||
if (currentContext == null || username == null) {
|
||||
onFailureCallback?.call();
|
||||
return;
|
||||
}
|
||||
|
||||
if (openAppDeepLinkData.isLoggedInWith(username.value)) {
|
||||
onFailureCallback?.call();
|
||||
return;
|
||||
}
|
||||
|
||||
_showConfirmDialogSwitchAccount(
|
||||
context: currentContext!,
|
||||
currentUsername: username.value,
|
||||
newUsername: openAppDeepLinkData.username,
|
||||
onConfirmAction: () => onConfirmLogoutCallback?.call(openAppDeepLinkData),
|
||||
onCancelAction: () => onFailureCallback?.call()
|
||||
);
|
||||
} else {
|
||||
autoSignInViaDeepLink(
|
||||
openAppDeepLinkData: openAppDeepLinkData,
|
||||
onAutoSignInSuccessCallback: (viewState) => onAutoSignInSuccessCallback?.call(viewState),
|
||||
onFailureCallback: () => onFailureCallback?.call(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> autoSignInViaDeepLink({
|
||||
required OpenAppDeepLinkData openAppDeepLinkData,
|
||||
required OnAutoSignInViaDeepLinkSuccessCallback onAutoSignInSuccessCallback,
|
||||
required OnDeepLinkFailureCallback onFailureCallback,
|
||||
}) async {
|
||||
try {
|
||||
final autoSignInViaDeepLinkInteractor = Get.find<AutoSignInViaDeepLinkInteractor>();
|
||||
|
||||
final autoSignInViewState = await autoSignInViaDeepLinkInteractor.execute(
|
||||
baseUri: openAppDeepLinkData.baseUri,
|
||||
tokenOIDC: openAppDeepLinkData.tokenOIDC,
|
||||
oidcConfiguration: openAppDeepLinkData.oidcConfiguration,
|
||||
).last;
|
||||
|
||||
autoSignInViewState.foldSuccess<AutoSignInViaDeepLinkSuccess>(
|
||||
onSuccess: onAutoSignInSuccessCallback,
|
||||
onFailure: (failure) => onFailureCallback.call(),
|
||||
);
|
||||
} catch (e) {
|
||||
logError('DeepLinksManager::_autoSignInViaDeepLink:Exception = $e');
|
||||
onFailureCallback.call();
|
||||
}
|
||||
}
|
||||
|
||||
void _showConfirmDialogSwitchAccount({
|
||||
required BuildContext context,
|
||||
required String currentUsername,
|
||||
required String newUsername,
|
||||
required Function onConfirmAction,
|
||||
required Function onCancelAction,
|
||||
}) {
|
||||
final appLocalizations = AppLocalizations.of(context);
|
||||
|
||||
showConfirmDialogAction(
|
||||
context,
|
||||
'',
|
||||
appLocalizations.yes,
|
||||
title: appLocalizations.switchAccountConfirmation,
|
||||
alignCenter: true,
|
||||
outsideDismissible: false,
|
||||
titleActionButtonMaxLines: 1,
|
||||
titlePadding: const EdgeInsetsDirectional.only(start: 24, top: 24, end: 24, bottom: 12),
|
||||
messageStyle: const TextStyle(
|
||||
color: AppColor.colorTextBody,
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w400,
|
||||
),
|
||||
listTextSpan: [
|
||||
TextSpan(text: appLocalizations.youAreCurrentlyLoggedInWith),
|
||||
TextSpan(
|
||||
text: ' $currentUsername',
|
||||
style: const TextStyle(
|
||||
color: AppColor.colorTextBody,
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const TextSpan(text: '. '),
|
||||
TextSpan(text: appLocalizations.doYouWantToLogOutAndSwitchTo),
|
||||
TextSpan(
|
||||
text: ' $newUsername',
|
||||
style: const TextStyle(
|
||||
color: AppColor.colorTextBody,
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const TextSpan(text: '?'),
|
||||
],
|
||||
onConfirmAction: onConfirmAction,
|
||||
onCancelAction: onCancelAction,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -4315,6 +4315,27 @@ class AppLocalizations {
|
||||
);
|
||||
}
|
||||
|
||||
String get switchAccountConfirmation {
|
||||
return Intl.message(
|
||||
'Switch Account Confirmation',
|
||||
name: 'switchAccountConfirmation',
|
||||
);
|
||||
}
|
||||
|
||||
String get youAreCurrentlyLoggedInWith {
|
||||
return Intl.message(
|
||||
'You are currently logged in with',
|
||||
name: 'youAreCurrentlyLoggedInWith',
|
||||
);
|
||||
}
|
||||
|
||||
String get doYouWantToLogOutAndSwitchTo {
|
||||
return Intl.message(
|
||||
'Do you want to log out and switch to',
|
||||
name: 'doYouWantToLogOutAndSwitchTo',
|
||||
);
|
||||
}
|
||||
|
||||
String get getHelpOrReportABug {
|
||||
return Intl.message(
|
||||
'Get help or report a bug',
|
||||
|
||||
@@ -19,7 +19,6 @@ class AppConfig {
|
||||
static const String linagoraPrivacyUrl = 'https://www.linagora.com/en/legal/privacy';
|
||||
static const String saasRegistrationUrl = 'https://sign-up.twake.app';
|
||||
static const String saasJmapServerUrl = 'https://jmap.twake.app';
|
||||
static const String openAppHostDeepLink = 'openApp';
|
||||
|
||||
static String get baseUrl => dotenv.get('SERVER_URL', fallback: '');
|
||||
static String get domainRedirectUrl => dotenv.get('DOMAIN_REDIRECT_URL', fallback: '');
|
||||
|
||||
@@ -82,7 +82,7 @@ class IOSSharingManager {
|
||||
userName: personalAccount.userName!
|
||||
);
|
||||
|
||||
final tokenRecords = await _getTokenEndpointAndScopes();
|
||||
final tokenRecords = await _getTokenEndpointScopesAndIsTWP();
|
||||
|
||||
final mailboxIdsBlockNotification = await _getMailboxIdsBlockNotification(
|
||||
accountId: personalAccount.accountId!,
|
||||
@@ -99,7 +99,9 @@ class IOSSharingManager {
|
||||
basicAuth: credentialInfo,
|
||||
tokenEndpoint: tokenRecords?.tokenEndpoint,
|
||||
oidcScopes: tokenRecords?.scopes,
|
||||
mailboxIdsBlockNotification: mailboxIdsBlockNotification);
|
||||
mailboxIdsBlockNotification: mailboxIdsBlockNotification,
|
||||
isTWP: tokenRecords?.isTWP ?? false,
|
||||
);
|
||||
|
||||
await _keychainSharingManager.save(keychainSharingSession);
|
||||
|
||||
@@ -171,13 +173,14 @@ class IOSSharingManager {
|
||||
}
|
||||
}
|
||||
|
||||
Future<({String? tokenEndpoint, List<String>? scopes})?> _getTokenEndpointAndScopes() async {
|
||||
Future<({String? tokenEndpoint, List<String>? scopes, bool isTWP})?> _getTokenEndpointScopesAndIsTWP() async {
|
||||
try {
|
||||
final oidcConfig = await _oidcConfigurationCacheManager.getOidcConfiguration();
|
||||
final oidcDiscoveryResponse = await _oidcHttpClient.discoverOIDC(oidcConfig);
|
||||
return (
|
||||
tokenEndpoint: oidcDiscoveryResponse.tokenEndpoint,
|
||||
scopes: oidcConfig.scopes
|
||||
scopes: oidcConfig.scopes,
|
||||
isTWP: oidcConfig.isTWP,
|
||||
);
|
||||
} catch (e) {
|
||||
logError('IOSSharingManager::_getTokenEndpointAndScopes:Exception: $e');
|
||||
|
||||
Reference in New Issue
Block a user