datalad_next.utils.DataladAuth

class datalad_next.utils.DataladAuth(cfg: ConfigManager, credential: str | None = None)[source]

Bases: AuthBase

Requests-style authentication handler using DataLad credentials

Similar to request_toolbelt's AuthHandler, this is a meta implementation that can be used with different actual authentication schemes. In contrast to AuthHandler, a credential can not only be specified directly, but credentials can be looked up based on the target URL and the server-supported authentication schemes.

In addition to programmatic specification and automated lookup, manual credential entry using interactive prompts is also supported.

At present, this implementation is not thread-safe.

handle_401(r, **kwargs)[source]

Callback that received any response to a request

Any non-4xx response or a response lacking a 'www-authenticate' header is ignored.

Server-provided 'www-authenticated' challenges are inspected, and corresponding credentials are looked-up (if needed) and subsequently tried in a re-request to the original URL after performing any necessary actions to meet a given challenge. Such a re-request is then using the same connection as the original request.

Particular challenges are implemented in dedicated classes, e.g. requests.auth.HTTPBasicAuth.

Credential look-up or entry is performed by datalad_next.requests_auth.DataladAuth._get_credential().

handle_redirect(r, **kwargs)[source]

Callback that received any response to a request

Any non-redirect response is ignore.

This callback drops an explicitly set credential whenever the redirect causes a non-encrypted connection to be used after the original request was encrypted, or when the netloc of the redirect differs from the original target.

save_entered_credential(suggested_name: str | None = None, context: str | None = None) Dict | None[source]

Utility method to save a pending credential in the store

Pending credentials have been entered manually, and were subsequently used successfully for authentication.

Saving a credential will prompt for entering a name to identify the credentials.