-
Notifications
You must be signed in to change notification settings - Fork 88
TF-3348 Move access token from persistent to memory #3404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tddang-linagora
wants to merge
3
commits into
maintenance-v0.14.2
Choose a base branch
from
fixbug/TF-3348-move-access-token-from-persistent-to-memory
base: maintenance-v0.14.2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
4da3b81
TF-3348 Move accessToken from persistent storage to session storage f…
tddang-linagora 34aedd8
fixup! TF-3348 Move accessToken from persistent storage to session st…
tddang-linagora e4a4267
fixup! TF-3348 Move accessToken from persistent storage to session st…
tddang-linagora File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
lib/features/login/data/local/web_token_oidc_cache_manager.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import 'package:core/utils/app_logger.dart'; | ||
import 'package:model/oidc/token_oidc.dart'; | ||
import 'package:tmail_ui_user/features/caching/clients/token_oidc_cache_client.dart'; | ||
import 'package:tmail_ui_user/features/login/data/extensions/token_oidc_cache_extension.dart'; | ||
import 'package:tmail_ui_user/features/login/data/extensions/token_oidc_extension.dart'; | ||
import 'package:tmail_ui_user/features/login/data/local/token_oidc_cache_manager.dart'; | ||
import 'package:tmail_ui_user/features/login/data/model/token_oidc_cache.dart'; | ||
import 'package:tmail_ui_user/features/login/domain/exceptions/authentication_exception.dart'; | ||
import 'package:universal_html/html.dart'; | ||
|
||
class WebTokenOidcCacheManager extends TokenOidcCacheManager { | ||
const WebTokenOidcCacheManager(this._tokenOidcCacheClient) | ||
: super(_tokenOidcCacheClient); | ||
|
||
final TokenOidcCacheClient _tokenOidcCacheClient; | ||
|
||
static const _sessionStorageTokenKey = 'twake_mail_token_session_storage'; | ||
|
||
@override | ||
Future<TokenOIDC> getTokenOidc(String tokenIdHash) async { | ||
log('WebTokenOidcCacheManager::getTokenOidc(): tokenIdHash: $tokenIdHash'); | ||
final tokenHiveCache = await _tokenOidcCacheClient.getItem(tokenIdHash); | ||
final tokenSessionStorageCache = window.sessionStorage[_sessionStorageTokenKey]; | ||
log('WebTokenOidcCacheManager::getTokenOidc(): tokenHiveCache: $tokenHiveCache'); | ||
log('WebTokenOidcCacheManager::getTokenOidc(): tokenSessionStorageCache: $tokenSessionStorageCache'); | ||
if (tokenHiveCache == null) { | ||
throw NotFoundStoredTokenException(); | ||
} else { | ||
return TokenOidcCache( | ||
tokenSessionStorageCache ?? 'dummy_token', | ||
tokenHiveCache.tokenId, | ||
tokenHiveCache.refreshToken, | ||
expiredTime: tokenSessionStorageCache != null | ||
? tokenHiveCache.expiredTime | ||
: DateTime.now().subtract(const Duration(hours: 1)), | ||
dab246 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
).toTokenOidc(); | ||
} | ||
} | ||
|
||
@override | ||
Future<void> persistOneTokenOidc(TokenOIDC tokenOIDC) async { | ||
log('TokenOidcCacheManager::persistOneTokenOidc(): $tokenOIDC'); | ||
await _tokenOidcCacheClient.clearAllData(); | ||
log('TokenOidcCacheManager::persistOneTokenOidc(): key: ${tokenOIDC.tokenId.uuid}'); | ||
log('TokenOidcCacheManager::persistOneTokenOidc(): key\'s hash: ${tokenOIDC.tokenIdHash}'); | ||
log('TokenOidcCacheManager::persistOneTokenOidc(): token: ${tokenOIDC.token}'); | ||
final tokenHiveCache = tokenOIDC.toTokenOidcCacheWithoutToken(); | ||
await _tokenOidcCacheClient.insertItem(tokenOIDC.tokenIdHash, tokenHiveCache); | ||
window.sessionStorage[_sessionStorageTokenKey] = tokenOIDC.token; | ||
log('TokenOidcCacheManager::persistOneTokenOidc(): done'); | ||
} | ||
|
||
@override | ||
Future<void> deleteTokenOidc() async { | ||
await _tokenOidcCacheClient.clearAllData(); | ||
window.sessionStorage.remove(_sessionStorageTokenKey); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import 'package:core/utils/file_utils.dart'; | ||
import 'package:core/utils/platform_info.dart'; | ||
import 'package:flutter_secure_storage/flutter_secure_storage.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:get/instance_manager.dart'; | ||
import 'package:mockito/annotations.dart'; | ||
import 'package:shared_preferences/shared_preferences.dart'; | ||
import 'package:tmail_ui_user/features/login/data/local/token_oidc_cache_manager.dart'; | ||
import 'package:tmail_ui_user/features/login/data/local/web_token_oidc_cache_manager.dart'; | ||
import 'package:tmail_ui_user/main/bindings/local/local_bindings.dart'; | ||
|
||
import 'local_bindings_test.mocks.dart'; | ||
|
||
@GenerateNiceMocks([ | ||
MockSpec<FlutterSecureStorage>(), | ||
MockSpec<SharedPreferences>(), | ||
MockSpec<FileUtils>(), | ||
]) | ||
void main() { | ||
late LocalBindings localBindings; | ||
|
||
setUp(() { | ||
localBindings = LocalBindings(); | ||
Get.put<FlutterSecureStorage>(MockFlutterSecureStorage()); | ||
Get.put<SharedPreferences>(MockSharedPreferences()); | ||
Get.put<FileUtils>(MockFileUtils()); | ||
}); | ||
|
||
group('local bindings test:', () { | ||
test( | ||
'should inject WebTokenOidcCacheManager ' | ||
'when platform is web', | ||
() { | ||
// arrange | ||
PlatformInfo.isTestingForWeb = true; | ||
localBindings.dependencies(); | ||
|
||
// act | ||
final cacheManager = Get.find<TokenOidcCacheManager>(); | ||
|
||
// assert | ||
expect(cacheManager, isInstanceOf<WebTokenOidcCacheManager>()); | ||
PlatformInfo.isTestingForWeb = false; | ||
}); | ||
|
||
test( | ||
'should inject TokenOidcCacheManager ' | ||
'when platform is not web (default)', | ||
() { | ||
// arrange | ||
localBindings.dependencies(); | ||
|
||
// act | ||
final cacheManager = Get.find<TokenOidcCacheManager>(); | ||
|
||
// assert | ||
expect(cacheManager, isInstanceOf<TokenOidcCacheManager>()); | ||
}); | ||
}); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.