class Bearer(ParentBearer): (source)
Constructor: Bearer(profile_name, client_id, federation_endpoint, federation_id, ...)
Bearer that exposes a federation interactive receiver.
The bearer is a lightweight wrapper that holds configuration used to
construct Receiver instances. It also exposes a stable
name used for caching and identification.
Interactive authorization flow (what happens on fetch)
When Receiver._fetch is invoked the implementation will call the
helper nebius.aio.token.federation_bearer.auth.authorize which
performs the interactive federation handshake. The typical flow is:
- The helper constructs an authorization URL and either attempts to open
- the user's default browser or returns the URL for the caller to display.
- The helper will block while waiting for the user to complete the
- authorization in the browser (for example by granting access). This means Receiver._fetch may hang until the user completes the flow.
- The helper receives an authorization response containing an access token
- and expiry. The receiver converts this into a
nebius.aio.token.token.Tokenand returns it to the caller.
Where the URL is shown
- The authorization URL is logged at INFO/DEBUG levels so it appears in the
- project's logs.
Blocking considerations
Because the flow waits for the user's action, callers should be aware that
fetch can block for an extended period. Use reasonable timeouts when
calling Receiver._fetch or invoke the bearer within a background
task if you need the application to remain responsive.
Example
Construct a bearer and use it to initialize the SDK:
from nebius.sdk import SDK
from nebius.aio.token.federation_bearer import Bearer
import sys
sdk = SDK(credentials=Bearer(
profile_name="not-a-cli-profile",
client_id="my-client-id",
federation_endpoint="auth.eu.nebius.com",
federation_id="federation-e00my-federation",
writer=sys.stdout,
no_browser_open=True,
))
| Parameters | |
| profile | Human-readable profile name that will be included in
name. |
| client | OAuth2 client identifier. |
| federation | Federation endpoint URL. |
| federation | Identifier of users federation. |
| writer | Optional text writer used to display instructions. |
| no | When true the receiver will not attempt to open a browser automatically. |
| ssl | Optional SSL context for HTTPS requests. |
| Method | __init__ |
Create a federation interactive bearer. |
| Method | receiver |
Return a new Receiver bound to this bearer's configuration. |
| Property | name |
Optional human-readable name for the bearer. |
| Instance Variable | _client |
Undocumented |
| Instance Variable | _federation |
Undocumented |
| Instance Variable | _federation |
Undocumented |
| Instance Variable | _no |
Undocumented |
| Instance Variable | _profile |
Undocumented |
| Instance Variable | _ssl |
Undocumented |
| Instance Variable | _tasks |
Undocumented |
| Instance Variable | _writer |
Undocumented |
Inherited from Bearer:
| Async Method | close |
Close the bearer and any wrapped resources. |
| Property | wrapped |
Return the wrapped bearer or None if not wrapping. |
str, client_id: str, federation_endpoint: str, federation_id: str, writer: TextIO | None = None, no_browser_open: bool = False, ssl_ctx: SSLContext | None = None):
(source)
¶
Create a federation interactive bearer.
nebius.aio.token.token.Bearer.receiverReturn a new Receiver bound to this bearer's configuration.
| Returns | |
ParentReceiver | A Receiver capable of performing the interactive
authorization flow. |
nebius.aio.token.token.Bearer.nameOptional human-readable name for the bearer.
This may be used in some wrapper providers to cache the results of the shared receiver, or to report diagnostics.
This name should reflect the unique configuration of the bearer.
If the bearer wraps another bearer, the default behaviour is to forward the name lookup to the wrapped instance.
| Returns | |
str or None | Undocumented |