class documentation

class TokenAuthenticator(Authenticator): (source)

Constructor: TokenAuthenticator(receiver)

View In Hierarchy

Per-request authenticator that injects a bearer token.

The authenticator uses a token.Receiver to fetch a token which is then written into the request metadata under the header named by HEADER as Bearer <token>. The instance holds a reference to the receiver and delegates retry decisions to the receiver via token.Receiver.can_retry.

Parameters
receiverToken receiver used to fetch tokens for each request.
Method __init__ Create a token authenticator.
Async Method authenticate Fetch a token from the receiver and set the authorization metadata header.
Method can_retry Delegate retry decision to the underlying token receiver.
Instance Variable _receiver Undocumented
def __init__(self, receiver: token.Receiver): (source)

Create a token authenticator.

async def authenticate(self, metadata: Metadata, timeout: float | None = None, options: dict[str, str] | None = None): (source)

Fetch a token from the receiver and set the authorization metadata header.

The header is replaced (any existing value is removed) with a Bearer <token> value fetched from the receiver.

Parameters
metadata:nebius.base.metadata.MetadataMetadata mapping sent with the request; mutated in place to include the Authorization header.
timeout:optional floatOptional timeout for the token fetch operation.
options:optional dict[str, str]Optional provider/request options passed through.
def can_retry(self, err: Exception, options: dict[str, str] | None = None) -> bool: (source)

Delegate retry decision to the underlying token receiver.

Parameters
err:ExceptionThe exception that caused the request/authentication to fail.
options:optional dict[str, str]Optional provider/request options.
Returns
boolTrue when the receiver indicates the operation should be retried (for example token refresh may succeed); False otherwise.
_receiver = (source)

Undocumented