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
+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/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/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/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/push_notification/data/extensions/keychain_sharing_session_extension.dart';
@@ -20,12 +22,16 @@ class IOSSharingManager {
final StateCacheManager _stateCacheManager;
final TokenOidcCacheManager _tokenOidcCacheManager;
final AuthenticationInfoCacheManager _authenticationInfoCacheManager;
final OidcConfigurationCacheManager _oidcConfigurationCacheManager;
final OIDCHttpClient _oidcHttpClient;
IOSSharingManager(
this._keychainSharingManager,
this._stateCacheManager,
this._tokenOidcCacheManager,
this._authenticationInfoCacheManager
this._authenticationInfoCacheManager,
this._oidcConfigurationCacheManager,
this._oidcHttpClient,
);
bool _validateToSaveKeychain(PersonalAccount personalAccount) {
@@ -69,6 +75,8 @@ class IOSSharingManager {
userName: personalAccount.userName!
);
final tokenRecords = await _getTokenEndpointAndScopes();
final keychainSharingSession = KeychainSharingSession(
accountId: personalAccount.accountId!,
userName: personalAccount.userName!,
@@ -77,7 +85,9 @@ class IOSSharingManager {
emailState: emailState,
emailDeliveryState: emailDeliveryState,
tokenOIDC: authenticationInfo.value1,
basicAuth: authenticationInfo.value2
basicAuth: authenticationInfo.value2,
tokenEndpoint: tokenRecords?.tokenEndpoint,
oidcScopes: tokenRecords?.scopes,
);
log('IOSSharingManager::_saveKeyChainSharingSession: $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 {
final keychainSharingStored = await getKeychainSharingSession(accountId);
log('IOSSharingManager::updateEmailStateInKeyChain:keychainSharingStored: $keychainSharingStored | newEmailState: $newEmailState');