init method

Future<void> init()

Initializes the user manager, this also gets the discoveryDocument if it wasn't provided.

The restore behavior depends on OidcUserManagerSettings.initMode:

  • OidcInitMode.cacheFirst (the default): a cached user is restored by a pure local deserialize (no network) and init() completes immediately, then the user is revalidated in the background. When there is no cached user / cached discovery document, this transparently falls back to the blocking network path below. Note this surfaces the user through userChanges TWICE on a cold start (restored-then-revalidated) — see OidcInitMode.cacheFirst for why the second emission is intentional.
  • OidcInitMode.blockingValidate: the previous semantics — block until the discovery document is fetched and the cached token fully re-verified. Not a byte-for-byte replica of the pre-1.0 network behavior unless combined with discoveryDocumentMaxAge: Duration.zero (the discovery document is otherwise served from its TTL cache).

Implementation

Future<void> init() {
  return initMemoizer.runOnce(() async {
    // Settle [userChangesAfterInit] listeners from in here rather than by
    // listening to [initFuture] (see [_userChangesAfterInitWaiters]): the
    // outcome is observed where it happens, and a failure is rethrown
    // unchanged so callers (and the zone, if nobody awaits) see it as
    // before.
    try {
      await _runInit();
    } on Object catch (e, st) {
      _initSettled = true;
      _settleUserChangesAfterInitWaiters(e, st);
      rethrow;
    }
    _initSettled = true;
    _settleUserChangesAfterInitWaiters(null, null);
  });
}