TF-2871 Fix missing tokenEndpoint & scopes passing to keychain

This commit is contained in:
dab246
2024-05-21 01:04:23 +07:00
committed by Dat H. Pham
parent ee739de19c
commit b48aa1fe2e
2 changed files with 30 additions and 2 deletions
@@ -16,6 +16,7 @@ import 'package:tmail_ui_user/features/email/data/network/mdn_api.dart';
import 'package:tmail_ui_user/features/home/data/network/session_api.dart'; import 'package:tmail_ui_user/features/home/data/network/session_api.dart';
import 'package:tmail_ui_user/features/login/data/local/account_cache_manager.dart'; import 'package:tmail_ui_user/features/login/data/local/account_cache_manager.dart';
import 'package:tmail_ui_user/features/login/data/local/authentication_info_cache_manager.dart'; import 'package:tmail_ui_user/features/login/data/local/authentication_info_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/local/token_oidc_cache_manager.dart';
import 'package:tmail_ui_user/features/login/data/network/authentication_client/authentication_client_base.dart'; import 'package:tmail_ui_user/features/login/data/network/authentication_client/authentication_client_base.dart';
import 'package:tmail_ui_user/features/login/data/network/dns_service.dart'; import 'package:tmail_ui_user/features/login/data/network/dns_service.dart';
@@ -77,6 +78,8 @@ class NetworkBindings extends Bindings {
Get.find<StateCacheManager>(), Get.find<StateCacheManager>(),
Get.find<TokenOidcCacheManager>(), Get.find<TokenOidcCacheManager>(),
Get.find<AuthenticationInfoCacheManager>(), Get.find<AuthenticationInfoCacheManager>(),
Get.find<OidcConfigurationCacheManager>(),
Get.find<OIDCHttpClient>(),
)); ));
} }
+27 -2
View File
@@ -8,7 +8,9 @@ import 'package:jmap_dart_client/jmap/core/user_name.dart';
import 'package:model/account/personal_account.dart'; import 'package:model/account/personal_account.dart';
import 'package:model/oidc/token_oidc.dart'; import 'package:model/oidc/token_oidc.dart';
import 'package:tmail_ui_user/features/login/data/local/authentication_info_cache_manager.dart'; import 'package:tmail_ui_user/features/login/data/local/authentication_info_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/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/mailbox/data/local/state_cache_manager.dart'; import 'package:tmail_ui_user/features/mailbox/data/local/state_cache_manager.dart';
import 'package:tmail_ui_user/features/mailbox/data/model/state_type.dart'; import 'package:tmail_ui_user/features/mailbox/data/model/state_type.dart';
import 'package:tmail_ui_user/features/push_notification/data/extensions/keychain_sharing_session_extension.dart'; import 'package:tmail_ui_user/features/push_notification/data/extensions/keychain_sharing_session_extension.dart';
@@ -20,12 +22,16 @@ class IOSSharingManager {
final StateCacheManager _stateCacheManager; final StateCacheManager _stateCacheManager;
final TokenOidcCacheManager _tokenOidcCacheManager; final TokenOidcCacheManager _tokenOidcCacheManager;
final AuthenticationInfoCacheManager _authenticationInfoCacheManager; final AuthenticationInfoCacheManager _authenticationInfoCacheManager;
final OidcConfigurationCacheManager _oidcConfigurationCacheManager;
final OIDCHttpClient _oidcHttpClient;
IOSSharingManager( IOSSharingManager(
this._keychainSharingManager, this._keychainSharingManager,
this._stateCacheManager, this._stateCacheManager,
this._tokenOidcCacheManager, this._tokenOidcCacheManager,
this._authenticationInfoCacheManager this._authenticationInfoCacheManager,
this._oidcConfigurationCacheManager,
this._oidcHttpClient,
); );
bool _validateToSaveKeychain(PersonalAccount personalAccount) { bool _validateToSaveKeychain(PersonalAccount personalAccount) {
@@ -69,6 +75,8 @@ class IOSSharingManager {
userName: personalAccount.userName! userName: personalAccount.userName!
); );
final tokenRecords = await _getTokenEndpointAndScopes();
final keychainSharingSession = KeychainSharingSession( final keychainSharingSession = KeychainSharingSession(
accountId: personalAccount.accountId!, accountId: personalAccount.accountId!,
userName: personalAccount.userName!, userName: personalAccount.userName!,
@@ -77,7 +85,9 @@ class IOSSharingManager {
emailState: emailState, emailState: emailState,
emailDeliveryState: emailDeliveryState, emailDeliveryState: emailDeliveryState,
tokenOIDC: authenticationInfo.value1, tokenOIDC: authenticationInfo.value1,
basicAuth: authenticationInfo.value2 basicAuth: authenticationInfo.value2,
tokenEndpoint: tokenRecords?.tokenEndpoint,
oidcScopes: tokenRecords?.scopes,
); );
log('IOSSharingManager::_saveKeyChainSharingSession: $keychainSharingSession'); log('IOSSharingManager::_saveKeyChainSharingSession: $keychainSharingSession');
await _keychainSharingManager.save(keychainSharingSession); await _keychainSharingManager.save(keychainSharingSession);
@@ -153,6 +163,21 @@ class IOSSharingManager {
} }
} }
Future<({String? tokenEndpoint, List<String>? scopes})?> _getTokenEndpointAndScopes() async {
try {
final oidcConfig = await _oidcConfigurationCacheManager.getOidcConfiguration();
final oidcDiscoveryResponse = await _oidcHttpClient.discoverOIDC(oidcConfig);
log('IOSSharingManager::_getTokenEndpointAndScopes:oidcDiscoveryResponse = $oidcDiscoveryResponse | oidcConfig = $oidcConfig');
return (
tokenEndpoint: oidcDiscoveryResponse.tokenEndpoint,
scopes: oidcConfig.scopes
);
} catch (e) {
logError('IOSSharingManager::_getTokenEndpointAndScopes:Exception: $e');
return null;
}
}
Future updateEmailStateInKeyChain(AccountId accountId, String newEmailState) async { Future updateEmailStateInKeyChain(AccountId accountId, String newEmailState) async {
final keychainSharingStored = await getKeychainSharingSession(accountId); final keychainSharingStored = await getKeychainSharingSession(accountId);
log('IOSSharingManager::updateEmailStateInKeyChain:keychainSharingStored: $keychainSharingStored | newEmailState: $newEmailState'); log('IOSSharingManager::updateEmailStateInKeyChain:keychainSharingStored: $keychainSharingStored | newEmailState: $newEmailState');