Skip to content

auth

auth

Authentication — the entry point of every crew_dcs program.

There is no global client in crew_dcs: an auth object is the client handle. It carries the three things every call needs — the Domo instance (domo_instance, e.g. "mycompany" for mycompany.domo.com), the credential, and a pooled httpx.AsyncClient for connection reuse — and you pass it explicitly as the first argument to every route function and entity class.

Pick the class that matches your credential

  • DomoTokenAuth — access token from Admin → Authentication → Access tokens. Recommended for scripts and automation (see the Authenticating to Domo guide for the access-token account pattern). Domo docs: Access Tokens KB.
  • DomoFullAuth — username + password, for interactive sessions.
  • DomoDeveloperAuth — OAuth2 client ID + secret from developer.domo.com, for the public platform API surface. Domo docs: API Authentication.
  • DomoJupyterFullAuth / DomoJupyterTokenAuth — the same two credentials used inside Domo's Jupyter Workspaces (both subclass DomoJupyterAuth).

The shared contract

Every class inherits from DomoAuth, so functions accept DomoAuth and work with any credential type:

  • auth.auth_header — the header dict get_data merges into each request (create_headers reads this).
  • await auth.get_auth_token() — retrieve or refresh the token.
  • await auth.who_am_i() — verify the credential works before doing real work; returns the API's user record.
  • await auth.close_session() — close the pooled httpx session.

Auth classes are dataclasses: construct once, reuse everywhere. Secrets are repr=False fields, so printing an auth object won't leak tokens.

Session pooling (and how to end it)

On first use, get_data caches one pooled httpx.AsyncClient on the auth object and reuses it across calls (controlled by RouteContext.reuse_session, default on) — this amortizes TCP/TLS handshakes in bulk operations. The pool stays open until you close it; short-lived scripts can rely on process exit, but long-running apps should close it explicitly, either with await auth.close_session() or by using the auth as an async context manager:

async with DomoTokenAuth(domo_access_token="...", domo_instance="mycompany") as auth:
    await get_access_tokens(auth)  # reuses one pooled session
# session closed here

Response caching (separate, opt-in)

Response caching is controlled per-call on RouteContext (cache_responses=True, optional cache_config), not on the auth object — see crew_dcs.client.context. Off by default; enable for read-heavy flows where the same GETs repeat.

It also exports get_secret, the one way to read a secret by name:

token = get_secret("DOMO_COMMUNITY_ACCESS_TOKEN")
auth = DomoTokenAuth(domo_access_token=token, domo_instance="domo-community")

Type Hinting: All authentication classes (DomoTokenAuth, DomoFullAuth, DomoDeveloperAuth, etc.) inherit from DomoAuth and implement the same interface via shared mixins, so functions can accept DomoAuth and work with any auth subclass.

SecretsProvider module-attribute

SecretsProvider = Callable[[str], str | None]

Takes a secret name, returns its value or None when it has none.

DomoAuth

Bases: ABC

Abstract contract for Domo authentication implementations.

All concrete auth classes must inherit from this class and provide the required authentication surface used by routes and entities.

auth_header abstractmethod property

auth_header: dict

Generate authentication headers for API requests.

url_manual_login property

url_manual_login: str

Generate the manual login URL for the Domo instance.

cache_stats

cache_stats() -> dict

Get HTTP cache statistics.

clear_cache

clear_cache() -> None

Clear all HTTP caches for this auth instance.

close_session async

close_session() -> None

Close and drop the pooled session cached on this auth, if any.

A reused session is otherwise held open until the auth is GC'd. Call this (or use the auth as an async context manager) for clean teardown::

async with DomoTokenAuth(...) as auth:
    await DomoCard.create(auth=auth, ...)   # reuses one pooled session
# session closed here

elevate_otp async

elevate_otp(
    one_time_password: str,
    debug_api: bool = False,
    session: AsyncClient | None = None,
    debug_num_stacks_to_drop: int = 2,
) -> ResponseGetData

Elevate the authentication to include OTP (One-Time Password) if required.

Calls route

get_auth_token abstractmethod async

get_auth_token(**context_kwargs) -> str | ResponseGetData

Retrieve or generate an authentication token.

invalidate_cache async

invalidate_cache(url_pattern: str) -> None

Manually invalidate cache entries matching URL pattern.

print_is_token async

print_is_token(
    token_name: str | None = None, **context_kwargs
) -> bool

Print token status and return True if token is valid, otherwise False.

set_cache_strategy

set_cache_strategy(strategy) -> None

Change cache invalidation strategy.

who_am_i async

who_am_i(**context_kwargs) -> ResponseGetData

Perform an API call to identify the user associated with the token.

Calls route

DomoDeveloperAuth dataclass

DomoDeveloperAuth(
    domo_client_id: str,
    domo_client_secret: str,
    domo_instance: str,
    token_name: str | None = None,
    token: str | None = None,
    user_id: str | None = None,
    is_valid_token: bool = False,
    cache_responses: bool = False,
    cache_size: int = 1000,
    cache_default_ttl: int = 300,
    cache_strategy: str | None = None,
    custom_cache_rules: dict[str, list[str]] | None = None,
)

Bases: DomoAuth

Developer authentication using client credentials.

This authentication method uses OAuth2 client credentials (client ID and secret) to obtain bearer tokens. This is typically used for applications built on Domo's developer platform and requires developer app registration.

Attributes:

Name Type Description
domo_client_id str

OAuth2 client ID from developer app registration

domo_client_secret str

OAuth2 client secret (not shown in repr)

domo_instance str

The Domo instance identifier

token_name str | None

Name identifier for the token

token str | None

The bearer token (not shown in repr)

user_id str | None

The authenticated user's ID

is_valid_token bool

Whether the current token is valid

cache_responses bool

Enable HTTP response caching (default: False)

cache_size int

Maximum number of cache entries (default: 1000)

cache_default_ttl int

Default cache TTL in seconds (default: 300)

cache_strategy str | None

Cache invalidation strategy (default: None, uses SMART)

custom_cache_rules dict | None

Custom cache invalidation rules (default: None)

Example

auth = DomoDeveloperAuth( ... domo_client_id="your-client-id", ... domo_client_secret="", # pragma: allowlist secret ... domo_instance="mycompany" ... ) token = await auth.get_auth_token()

auth_header property

auth_header: dict

Generate the authentication header for developer token authentication.

get_auth_token async

get_auth_token(**context_kwargs) -> str

Retrieve the developer token using client credentials and update internal attributes.

Calls route

who_am_i async

who_am_i(**context_kwargs) -> ResponseGetData

Use cached user_id from get_auth_token response (no separate API call).

DomoFullAuth dataclass

DomoFullAuth(
    domo_instance: str,
    domo_username: str,
    domo_password: str,
    token_name: str | None = None,
    token: str | None = None,
    user_id: str | None = None,
    is_valid_token: bool = False,
    cache_responses: bool = False,
    cache_size: int = 1000,
    cache_default_ttl: int = 300,
    cache_strategy: str | None = None,
    custom_cache_rules: dict[str, list[str]] | None = None,
)

Bases: DomoAuth

Full authentication using Domo username and password.

This class provides authentication using Domo credentials (username and password) to obtain session tokens. It's typically used for direct user authentication where username/password login is permitted.

Attributes:

Name Type Description
domo_instance str

The Domo instance identifier

domo_username str

Domo username for authentication

domo_password str

Domo password for authentication (not shown in repr)

token_name str | None

Name identifier for the token

token str | None

The authentication token (not shown in repr)

user_id str | None

The authenticated user's ID

is_valid_token bool

Whether the current token is valid

cache_responses bool

Enable HTTP response caching (default: False)

cache_size int

Maximum number of cache entries (default: 1000)

cache_default_ttl int

Default cache TTL in seconds (default: 300)

cache_strategy str | None

Cache invalidation strategy (default: None, uses SMART)

custom_cache_rules dict | None

Custom cache invalidation rules (default: None)

auth_header property

auth_header: dict

Generate the full authentication header specific to product APIs.

get_auth_token async

get_auth_token(
    return_raw: bool = False, **context_kwargs
) -> str | ResponseGetData

Retrieve the authentication token from product APIs using the provided credentials.

Calls route

DomoJupyterAuth

Mixin for Jupyter auth. Not instantiable alone.

Provides jupyter_token, service_location, service_prefix validation and jupyter_auth_header. Use DomoJupyterFullAuth or DomoJupyterTokenAuth.

jupyter_auth_header property

jupyter_auth_header: dict

Header for Jupyter server API (Authorization: Token ...).

DomoJupyterFullAuth dataclass

DomoJupyterFullAuth(
    jupyter_token: str,
    service_location: str,
    service_prefix: str,
    domo_instance: str,
    domo_username: str,
    domo_password: str,
    token_name: str | None = None,
    token: str | None = None,
    user_id: str | None = None,
    is_valid_token: bool = False,
    cache_responses: bool = False,
    cache_size: int = 1000,
    cache_default_ttl: int = 300,
    cache_strategy: str | None = None,
    custom_cache_rules: dict[str, list[str]] | None = None,
)

Bases: DomoJupyterAuth, DomoAuth

Jupyter authentication using full credentials (username/password).

auth_header property

auth_header: dict

Combined Domo + Jupyter headers (no guard — Jupyter token always present).

convert_auth classmethod

convert_auth(
    auth: DomoFullAuth,
    jupyter_token: str,
    service_location: str,
    service_prefix: str,
) -> DomoJupyterFullAuth

Create DomoJupyterFullAuth from DomoFullAuth + Jupyter params.

get_auth_token async

get_auth_token(
    return_raw: bool = False, **context_kwargs
) -> str | ResponseGetData

Retrieve the authentication token from product APIs.

Calls route

DomoJupyterTokenAuth dataclass

DomoJupyterTokenAuth(
    jupyter_token: str,
    service_location: str,
    service_prefix: str,
    domo_instance: str,
    domo_access_token: str,
    token_name: str | None = None,
    token: str | None = None,
    user_id: str | None = None,
    is_valid_token: bool = False,
    cache_responses: bool = False,
    cache_size: int = 1000,
    cache_default_ttl: int = 300,
    cache_strategy: str | None = None,
    custom_cache_rules: dict[str, list[str]] | None = None,
)

Bases: DomoJupyterAuth, DomoAuth

Jupyter authentication using access tokens.

auth_header property

auth_header: dict

Combined Domo + Jupyter headers (no guard — both tokens always present).

convert_auth classmethod

convert_auth(
    auth: DomoTokenAuth,
    jupyter_token: str,
    service_location: str,
    service_prefix: str,
) -> DomoJupyterTokenAuth

Create DomoJupyterTokenAuth from DomoTokenAuth + Jupyter params.

get_auth_token async

get_auth_token(
    token_name: str | None = None, **context_kwargs
) -> str

Retrieve the access token, validating via who_am_i if needed.

DomoTokenAuth dataclass

DomoTokenAuth(
    domo_access_token: str,
    domo_instance: str,
    token_name: str | None = None,
    token: str | None = None,
    user_id: str | None = None,
    is_valid_token: bool = False,
    cache_responses: bool = False,
    cache_size: int = 1000,
    cache_default_ttl: int = 300,
    cache_strategy: str | None = None,
    custom_cache_rules: dict[str, list[str]] | None = None,
)

Bases: DomoAuth

Token-based authentication using pre-generated access tokens.

This authentication method uses access tokens generated from Domo's admin panel (Admin > Access Tokens). This is particularly useful in environments where direct username/password authentication is not permitted or for automated systems.

Attributes:

Name Type Description
domo_access_token str

Pre-generated access token (not shown in repr)

domo_instance str

The Domo instance identifier

token_name str | None

Name identifier for the token

token str | None

The authentication token (not shown in repr)

user_id str | None

The authenticated user's ID

is_valid_token bool

Whether the current token is valid

cache_responses bool

Enable HTTP response caching (default: False)

cache_size int

Maximum number of cache entries (default: 1000)

cache_default_ttl int

Default cache TTL in seconds (default: 300)

cache_strategy str | None

Cache invalidation strategy (default: None, uses SMART)

custom_cache_rules dict | None

Custom cache invalidation rules (default: None)

auth_header property

auth_header: dict

Generate the authentication header for access token based authentication.

get_auth_token async

get_auth_token(
    token_name: str | None = None, **context_kwargs
) -> str

Retrieve the access token, updating internal attributes as necessary.

RecursiveSecretsProviderError

RecursiveSecretsProviderError(provider_name: str)

Bases: AuthError

The configured secrets provider called get_secret without a provider.

That call would resolve the configured provider again and never return. A provider that needs a secret of its own passes an explicit provider=.

SecretNotFoundError

SecretNotFoundError(secret_name: str, provider_name: str)

Bases: AuthError

The secrets provider has no value for the requested secret name.

get_secret

get_secret(
    name: str, provider: SecretsProvider | None = None
) -> str

Return the secret name from a secrets provider.

The provider is, in order: provider when passed; else the function named by the CREW_DCS_SECRETS_PROVIDER setting (package.module:function, read from the environment or the repo-root .env); else env_provider.

Raises:

Type Description
SecretNotFoundError

the provider returned None or an empty string.

ValueError

CREW_DCS_SECRETS_PROVIDER is not a package.module:function path.

TypeError

CREW_DCS_SECRETS_PROVIDER names something that is not callable.

RecursiveSecretsProviderError

the configured provider called get_secret without provider=.

test_is_full_auth

test_is_full_auth(
    auth,
    function_name: str | None = None,
    debug_num_stacks_to_drop: int = 1,
) -> None

Test that the provided object is a DomoFullAuth instance.

This validation function ensures that the authentication object is of the correct type for functions that specifically require full authentication.

Parameters:

Name Type Description Default
auth

The authentication object to validate

required
function_name str | None

Override function name for error reporting

None
debug_num_stacks_to_drop int

Number of stack frames to drop for debugging

1

Raises:

Type Description
AuthError

If auth is not a DomoFullAuth instance

test_is_jupyter_auth

test_is_jupyter_auth(
    auth, required_auth_type_ls: list | None = None
) -> None

Test that the provided object is a valid Jupyter authentication instance.

This validation function ensures that the authentication object is one of the accepted Jupyter authentication types for functions that specifically require Jupyter authentication capabilities.

Parameters:

Name Type Description Default
auth

The authentication object to validate

required
required_auth_type_ls list | None

list of acceptable auth types. Defaults to [DomoJupyterFullAuth, DomoJupyterTokenAuth]

None

Raises:

Type Description
AuthError

If auth is not one of the required Jupyter auth types

Modules