class documentation

Abstract asynchronous token receiver interface.

Implementations fetch bearer tokens from an external source (for example an OAuth token endpoint or a local cache) and expose a small API that the request layer uses to obtain tokens for per-request authentication.

The receiver is responsible for fetching and refreshing the token for one request only, reflecting the authentication process, while the Bearer class supports multiple requests and provides per-request receivers on demand.

Method can_retry Decide whether a failed authentication attempt should be retried.
Async Method fetch Fetch a token and record it as the latest value.
Property latest Return the latest fetched token or None.
Async Method _fetch Low-level asynchronous fetch implementation.
Instance Variable _latest The most recently fetched token, or None if no token has been fetched yet. Implementations may update this to support inspection or caching by callers.
@abstractmethod
def can_retry(self, err: Exception, options: dict[str, str] | None = None) -> bool: (source)

Decide whether a failed authentication attempt should be retried.

Implementations inspect err (for example gRPC status codes or specific exception types) and optional options to decide whether a fresh call to fetch is likely to succeed (for example after refreshing credentials).

Default implementations should return False.

Parameters
err:ExceptionThe exception that triggered the retry decision.
options:dict[str, str] or NoneOptional implementation-specific options.
Returns
boolTrue when a retry is advisable, otherwise False.
async def fetch(self, timeout: float | None = None, options: dict[str, str] | None = None) -> Token: (source)

Fetch a token and record it as the latest value.

This method calls the concrete _fetch implementation and stores the result on _latest before returning it.

Parameters
timeout:optional floatOptional timeout in seconds forwarded to the fetch.
options:optional dict[str, str]Optional implementation-specific options.
Returns
TokenThe fetched Token.
@property
latest: Token or None = (source)

Return the latest fetched token or None.

@abstractmethod
async def _fetch(self, timeout: float | None = None, options: dict[str, str] | None = None) -> Token: (source)

Low-level asynchronous fetch implementation.

Subclasses must implement this method to perform the actual token retrieval. This method is intentionally prefixed with an underscore to indicate it is the minimal primitive; callers should use fetch which records the result in _latest.

Parameters
timeout:optional floatOptional timeout in seconds for the fetch operation.
options:optional dict[str, str]Optional implementation-specific options forwarded by the request layer.
Returns
TokenA freshly fetched Token.

The most recently fetched token, or None if no token has been fetched yet. Implementations may update this to support inspection or caching by callers.