ClientAuthMixin#

class httpx_gracedb.auth.ClientAuthMixin(url=None, token=None, username=None, password=None, force_noauth=False, fail_if_noauth=False, auth_reload=False, auth_reload_timeout=300, **kwargs)[source]#

Bases: BaseClient

A mixin for httpx.Client to add support for all GraceDB authentication mechanisms.

Parameters:
  • url (str | None) – GraceDB Client URL.

  • token (str | Path | None) – Filename for SciTokens bearer token.

  • username (str | None) – Username for basic auth.

  • password (str | None) – Password for basic auth.

  • force_noauth (bool) – If true, then do not use any authentication at all.

  • fail_if_noauth (bool) – If true, then raise an exception if authentication credentials are not provided.

  • auth_reload (bool) – If true, then automatically reload the authentication before it expires.

  • auth_reload_timeout (float) – Reload the authentication this many seconds before it expires.

  • kwargs – Extra arguments passed to httpx.Client.

Notes

When a new Client instance is created, the following sources of authentication are tried, in order:

  1. If the force_noauth keyword argument is true, then perform no authentication at all.

  2. If the token keyword argument is provided, then use SciTokens bearer token authentication.

  3. If the username and password keyword arguments are provided, then use basic auth.

  4. Look for a SciTokens bearer token in:

    1. the environment variable BEARER_TOKEN_FILE

    2. the file $XDG_RUNTIME_DIR/bt_uUID, where UID is your numeric user ID, if the file exists and is readable

  5. Read the netrc file [1] located at ~/.netrc, or at the path stored in the environment variable NETRC, and look for a username and password matching the hostname in the URL.

  6. If the fail_if_noauth keyword argument is true, and no authentication source was found, then raise a ValueError.

References