class documentation

Abstract asynchronous token receiver interface.

Implementations get bearer tokens from an external source, such as an OAuth endpoint or local cache. The request layer uses this interface for per-request authentication.

A receiver gets and refreshes a token for one request. A Bearer supports multiple requests and supplies a receiver for each request.

The built-in channel calls receivers on its internal SDK event loop. A custom receiver must be thread-safe and loop-neutral. It must not retain asyncio state that belongs to an application loop.

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.

Inspect err and optional options. Return whether a new fetch call is likely to succeed, for example after credential refresh.

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 token-retrieval method. Call fetch instead of this internal method. fetch 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.