-
Notifications
You must be signed in to change notification settings - Fork 95
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.
+143
−6
Open
Changes from 1 commit
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
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/login/data/extensions/token_oidc_cache_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(super.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', | ||
dab246 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 = TokenOidcCache( | ||
'', | ||
tokenOIDC.tokenId.uuid, | ||
tokenOIDC.refreshToken, | ||
expiredTime: tokenOIDC.expiredTime, | ||
); | ||
dab246 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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
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.