Skip to content

bloqade.core.device.mixins.AuthMixin

← Module overview

classAuthMixinsource

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

NameTypeDefaultDescription
context_namestrrequired
qpu_modestr | NoneNone

propertyapp_contextsource

bloqade.core.device.mixins.AuthMixin.app_context

app_context: AppContext

The AppContext used to authenticate and connect to the backend.

Returns

AppContextAppContext: An app context scoped to `context_name`.

source

methodauthenticatesource

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.

source

methodcall_with_auth_refreshsource

bloqade.core.device.mixins.AuthMixin.call_with_auth_refresh

def call_with_auth_refresh(fn: Callable[[], T]) -> T

Run 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

NameTypeDescription
fnCallable[[], T]Zero-argument callable that performs the qlam API call.

Returns

TT: he value returned by `fn`.

Raises

TypeDescription
APIErrorWhen `fn` raises an `APIError` whose status is neither 401 nor 403, when refresh produces no fresh credentials, or when the retry also fails.
source