Auth Handlers#

The auth handlers plugin hook allows plugin authors to enable new modes of authentication within conda. Registered auth handlers will be available to configure on a per channel basis via the channel_settings configuration option in the .condarc file.

Auth handlers are subclasses of the ChannelAuthBase class, which is itself a subclass of requests.auth.AuthBase. The ChannelAuthBase class adds an additional channel_name property to the requests.auth.AuthBase class. This is necessary for appropriate handling of channel based authentication in conda.

For more information on how to implement your own auth handlers, please read the requests documentation on Custom Authentication.

class CondaAuthHandler#

Return type to use when the defining the conda auth handlers hook.

Parameters:
  • name -- Name (e.g., basic-auth). This name should be unique and only one may be registered at a time.

  • handler -- Type that will be used as the authentication handler during network requests.

handler#
name#
conda_auth_handlers()#

Register a conda auth handler derived from the requests API.

This plugin hook allows attaching requests auth handler subclasses, e.g. when authenticating requests against individual channels hosted at HTTP/HTTPS services.

Example:

import os
from conda import plugins
from requests.auth import AuthBase


class EnvironmentHeaderAuth(AuthBase):
    def __init__(self, *args, **kwargs):
        self.username = os.environ["EXAMPLE_CONDA_AUTH_USERNAME"]
        self.password = os.environ["EXAMPLE_CONDA_AUTH_PASSWORD"]

    def __call__(self, request):
        request.headers["X-Username"] = self.username
        request.headers["X-Password"] = self.password
        return request


@plugins.hookimpl
def conda_auth_handlers():
    yield plugins.CondaAuthHandler(
        name="environment-header-auth",
        auth_handler=EnvironmentHeaderAuth,
    )