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 proactive refresh any more, in the deprecated API too. Refresh happens on validToken, authorize or a rejected token. If you relied on infoDelegate for refresh before expiry, you lose it until you call validToken before each use. Proactive refresh is planned for a later release.
  • initialize() no longer rewrites storage; it only loads lazily. It is still required when you use the synchronous deprecated tokens getter or the 0.1 dio/grpc adapters, which never trigger a load themselves.
  • The deprecated executeRefresh() no longer swallows errors that are not Exceptions: 0.1 used catch (e), so a TypeError from a delegate now propagates.
  • refreshDelay is ignored. There is no retry timer; a transient failure is retried by the next call to validToken.
  • A refresher should throw InvalidGrant only when the refresh token was rejected for good. Everything else keeps the session.
  • skew defaults to 30 seconds; the old refreshThreshold defaulted to 3 minutes. Pass skew: Duration(minutes: 3) to keep the old margin.
  • The minimum SDK is 3.10.

Classes

TokenManagerRefreshDelegate<T> Migrating from 0.1
Defines how TokenManager refreshes expired tokens.
TokenStorage<T> Migrating from 0.1
Interface for storing and retrieving authentication tokens.

Typedefs

TokenInfoDelegate<T> = TokenInfo<T> Migrating from 0.1
Supplies metadata required to schedule proactive token refresh.

Exceptions / Errors

RevokedTokensException Migrating from 0.1
Exception thrown when tokens have been revoked and are no longer valid.