bloqade.core.device.mixins.AuthMixin
classAuthMixin¶source
bloqade.core.device.mixins.AuthMixin
Bases: ConfigMixin
Mixin that provides authentication helpers for qlam API clients.
class AuthMixin(*, context_name: str, qpu_mode: str | None = None)Inherits qlam configuration from ConfigMixin and manages an
AppContext scoped to context_name. Ensures the client is
authenticated before making API calls.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
context_name | str | required | |
qpu_mode | str | None | None |
propertyapp_context¶source
bloqade.core.device.mixins.AuthMixin.app_context
app_context: AppContextThe AppContext used to authenticate and connect to the backend.
Returns
AppContextAppContext: An app context scoped to `context_name`.
methodauthenticate¶source
bloqade.core.device.mixins.AuthMixin.authenticate
def authenticate()Ensure the client is authenticated, triggering a login if needed.
Returns
The login result when a login is performed; otherwise None.
methodcall_with_auth_refresh¶source
bloqade.core.device.mixins.AuthMixin.call_with_auth_refresh
def call_with_auth_refresh(fn: Callable[[], T]) -> TRun a qlam API call, refreshing credentials once on a 401 or 403.
If fn raises an APIError with status 401 (token expired) or 403
(access denied), a best-effort non-interactive credential refresh is
attempted via AuthClient. When the refresh updates at least one
provider’s credentials, fn is invoked again. Any other error, or a
refresh that produces no fresh credentials, propagates the original
exception.
Only one retry is attempted; a second 401/403 is re-raised.
Parameters
| Name | Type | Description |
|---|---|---|
fn | Callable[[], T] | Zero-argument callable that performs the qlam API call. |
Returns
TT: he value returned by `fn`.
Raises
| Type | Description |
|---|---|
APIError | When `fn` raises an `APIError` whose status is neither 401 nor 403, when refresh produces no fresh credentials, or when the retry also fails. |