class documentation
class TokenAuthenticator(Authenticator): (source)
Constructor: TokenAuthenticator(receiver)
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 | |
| receiver | Token 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 |
Delegate retry decision to the underlying token receiver. |
| Instance Variable | _receiver |
Undocumented |
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.Metadata | Metadata mapping sent with the request; mutated in place to include the Authorization header. |
timeout:optional float | Optional timeout for the token fetch operation. |
| options:optional dict[str, str] | Optional provider/request options passed through. |
Delegate retry decision to the underlying token receiver.
| Parameters | |
err:Exception | The exception that caused the request/authentication to fail. |
| options:optional dict[str, str] | Optional provider/request options. |
| Returns | |
| bool | True when the receiver indicates the operation should be
retried (for example token refresh may succeed); False otherwise. |