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:
BaseClientA mixin for
httpx.Clientto 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:
If the
force_noauthkeyword argument is true, then perform no authentication at all.If the
tokenkeyword argument is provided, then use SciTokens bearer token authentication.If the
usernameandpasswordkeyword arguments are provided, then use basic auth.Look for a SciTokens bearer token in:
the environment variable
BEARER_TOKEN_FILEthe file
$XDG_RUNTIME_DIR/bt_uUID, whereUIDis your numeric user ID, if the file exists and is readable
Read the netrc file [1] located at
~/.netrc, or at the path stored in the environment variableNETRC, and look for a username and password matching the hostname in the URL.If the
fail_if_noauthkeyword argument is true, and no authentication source was found, then raise aValueError.
References