Skip to main content

Module oauth_refresh

Module oauth_refresh 

Source
Expand description

Per-provider OAuth refresh coalesce.

refresh_if_expired looks up the stored OAuth credential for a provider and, if it is expired (or within 60 s of expiry), refreshes it via provider_oauth::refresh_grant. Concurrent callers for the same provider share a single in-flight refresh — once one finishes, all subsequent callers see the freshly stored token without making a second network request.

§Storage injection

The public entry point reads from the process-wide shared_auth_storage singleton. The inner refresh_if_expired_with_storage helper accepts an explicit &Arc<AuthStorage> so tests can drive an in-memory storage without touching the real auth.json. This mirrors the controller’s pre-flight API-alignment note: callers must NOT assume a method like auth.get_api_key_full exists — we read the full credential set via auth.get_all() and pattern-match the OAuth variant.

Enums§

RefreshError

Functions§

invalidate_coalesce
Drop the coalesce cell for provider so the next call to refresh_if_expired is forced to do a fresh refresh. Intended for tests and for error-recovery paths that want to invalidate a failed cell so a retry actually retries instead of returning the cached RefreshError::Failed.
refresh_if_expired
Refresh the stored OAuth credential for provider if it is expired or within 60 seconds of expiry. Concurrent calls coalesce on a per-provider OnceCell so the network round-trip runs at most once per cycle.
refresh_if_expired_with_storage
Inner helper: refresh against an explicit AuthStorage.