TokenExpiryManager class

Tracks the access-token expiry and refreshes the token when needed, making sure only one refresh runs at a time.

A missing, unreadable or corrupt expiry is always treated as expired.

Constructors

TokenExpiryManager({required SecureStorageRepository storage, required SecureTokenStorage tokenStorage, DateTime now()?, Duration defaultRefreshBuffer = const Duration(seconds: 60)})
Throws ArgumentError when defaultRefreshBuffer is negative.

Properties

defaultRefreshBuffer → Duration
How long before the expiry a token already counts as "should refresh".
final
expiryKey → String
Storage key of the expiry timestamp.
no setter
hashCode → int
The hash code for this object.
no setterinherited
isRefreshing → bool
Whether a refresh is running right now.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

clearExpiry() → Future<SecurityResult<void>>
getExpiry() → Future<SecurityResult<DateTime?>>
The stored expiry (UTC), or null when missing or corrupt.
isTokenExpired() → Future<bool>
true when the token has expired or no valid expiry is known.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
refreshIfNeeded(TokenRefresher refresher, {Duration? buffer, bool force = false, bool requireRefreshToken = true}) → Future<SecurityResult<String>>
Returns a usable access token, refreshing it first when necessary.
setExpiresIn(Duration lifetime) → Future<SecurityResult<void>>
Persists an expiry relative to now (e.g. an OAuth expires_in).
setExpiry(DateTime expiresAt) → Future<SecurityResult<void>>
Persists the absolute expiry of the access token.
shouldRefreshToken({Duration? buffer}) → Future<bool>
true when the token expires within buffer (default defaultRefreshBuffer), has expired, or no valid expiry is known.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited