OAuthTokenManager class

OAuth token manager with automatic refresh

Constructors

OAuthTokenManager(HttpOAuthClient _client)

Properties

currentToken OAuthToken?
Current token
no setter
hashCode int
The hash code for this object.
no setterinherited
hasValidToken bool
Check if we have a valid token
no setter
isAuthenticated bool
Check if the user is authenticated (alias for hasValidToken)
no setter
isTokenExpired bool
Check if token is expired
no setter
lifecycleEvents Stream<TokenLifecycleEvent>
Stream of token lifecycle events.
no setter
onBackgroundRefresh ↔ dynamic Function()?
getter/setter pair
onError Stream<OAuthError>
Stream of authentication errors
no setter
onRefreshFailure ↔ dynamic Function(dynamic error, int attempt)?
getter/setter pair
onTokenRefresh ↔ dynamic Function(OAuthToken oldToken, OAuthToken newToken)?
getter/setter pair
onTokenUpdate Stream<OAuthToken>
Stream of token updates
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

checkTokenExpiry() Future<void>
Checks token expiry and emits a near-expiry lifecycle event when due.
cleanupExpiredTokens() Future<int>
Drops expired tokens from memory.
clearToken() → void
Clear the current token
dispose() → void
Dispose resources
getAccessToken() Future<String>
Get a valid access token, refreshing if necessary
loadEncryptedToken(String encryptionKey) Future<OAuthToken?>
Loads an encrypted token.
loadPersistedTokens() Future<void>
Loads previously persisted tokens.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
refreshToken(OAuthToken newToken) Future<void>
Replaces the current token with newToken and fires the refresh callback.
revokeToken() Future<void>
Revokes the current token at the authorization server and clears it locally.
securelyDeleteToken() Future<void>
Securely deletes the token from memory.
setToken(OAuthToken token) → void
Set the current token and schedule refresh
startBackgroundRefresh() → void
Starts the background refresh timer.
stopBackgroundRefresh() → void
Stops the background refresh timer.
storeEncryptedToken(OAuthToken token, String encryptionKey) Future<void>
Stores an encrypted token.
storeToken(OAuthToken token, {bool persistent = false}) Future<void>
Stores the token in memory; persists to secure storage when persistent is true.
toString() String
A string representation of this object.
inherited
willExpireSoon({Duration threshold = const Duration(minutes: 5)}) bool
Returns true if the token will expire within threshold.

Operators

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