Migrating from 0.1 topic
Migrating from 0.1 to 0.2
The old API still works in 0.2, marked @Deprecated. It will be removed two
releases after 0.2.
Mapping
| 0.1 | 0.2 |
|---|---|
TokenManager(storage:, refreshDelegate:, infoDelegate:) |
TokenManager.create(store:, refresher:, info:, skew:) |
TokenStorage<T>: getTokens() / setTokens(T?) |
TokenStore<T>: read() / write(T) / delete() |
TokenManagerRefreshDelegate<T>.refresh |
TokenRefresher<T>.refresh |
refreshThreshold |
skew |
TokenInfoDelegate<T> |
TokenInfo<T> (same method) |
throw RevokedTokensException |
throw InvalidGrant |
tokens |
await current() or states |
tokensStream |
states (Unauthenticated replaces null) |
initialize() |
not needed, except for the sync tokens getter and 0.1 adapters |
executeRefresh() / waitForFresh |
validToken() |
setTokens(null) |
logout() |
Before and after
// 0.1
final manager = TokenManager<MyTokens>(
storage: MyStorage(),
refreshDelegate: MyDelegate(),
infoDelegate: MyInfo(),
);
await manager.initialize();
// 0.2
final manager = TokenManager<MyTokens>.create(
store: MyStore(),
refresher: MyRefresher(),
info: MyInfo(),
);
final tokens = await manager.validToken();
Behaviour changes
- There is no background timer any more, in the deprecated API too. Refresh
happens on
validToken,authorizeor a rejected token. If you relied oninfoDelegatefor refresh before expiry, passrefreshAheadtoTokenManager.create(0.2.3 and later) to refresh close-to-expiry tokens in the background on the nextvalidToken, or callrefreshIfNeeded()at start-up and when the app resumes. initialize()no longer rewrites storage; it only loads lazily. It is still required when you use the synchronous deprecatedtokensgetter or the 0.1 dio/grpc adapters, which never trigger a load themselves.- The deprecated
executeRefresh()no longer swallows errors that are notExceptions: 0.1 usedcatch (e), so aTypeErrorfrom a delegate now propagates. refreshDelayis ignored. There is no retry timer; a transient failure is retried by the next call tovalidToken.- A refresher should throw
InvalidGrantonly when the refresh token was rejected for good. Everything else keeps the session. skewdefaults to 30 seconds; the oldrefreshThresholddefaulted to 3 minutes. Passskew: Duration(minutes: 3)to keep the old margin.- The minimum SDK is 3.10.
Classes
-
TokenManagerRefreshDelegate<
T> - Defines how TokenManager refreshes expired tokens.
-
TokenStorage<
T> - Interface for storing and retrieving authentication tokens.
Typedefs
-
TokenInfoDelegate<
T> = TokenInfo< T> - Supplies metadata required to schedule proactive token refresh.
Exceptions / Errors
- RevokedTokensException
- Exception thrown when tokens have been revoked and are no longer valid.