invalidateAccessToken method

Future<bool> invalidateAccessToken(
  1. String? deadAccessToken
)

Evict a token the API has refused, if the cache still holds it.

Called when the refresh that should have replaced it failed: the cache is shared by every process running as this user, and a dead token left in it would be read, sent and refused by every later process.

A compare-and-clear rather than a bare clear: between the 401 and this call another worker may have refreshed and written a live token. On these credentials a new grant invalidates the previous token, so every worker minting its own would leave them taking turns being refused.

Under the same lock _renew writes through, so the read and the clear cannot straddle another process's write.

deadAccessToken is the token that produced the 401. Null or empty names no token and evicts nothing: clearing on "I do not know which" would discard a live entry. Returns whether an entry was removed.

Implementation

Future<bool> invalidateAccessToken(String? deadAccessToken) async {
  if (deadAccessToken == null || deadAccessToken.isEmpty) return false;
  return _store.withLock(_namespace, () {
    final record = _store.read(_namespace);
    if (record == null || record.accessToken != deadAccessToken) return false;
    _store.clear(_namespace);
    return true;
  });
}