b.t.h._.AbstractAuthHandler(urllib2.BaseHandler) : class documentation

Part of bzrlib.transport.http._urllib2_wrappers View In Hierarchy

Known subclasses: bzrlib.transport.http._urllib2_wrappers.BasicAuthHandler, bzrlib.transport.http._urllib2_wrappers.DigestAuthHandler, bzrlib.transport.http._urllib2_wrappers.HTTPAuthHandler, bzrlib.transport.http._urllib2_wrappers.NegotiateAuthHandler, bzrlib.transport.http._urllib2_wrappers.ProxyAuthHandler

A custom abstract authentication handler for all http authentications.

Provides the meat to handle authentication errors and preventively set authentication headers after the first successful authentication.

This can be used for http and proxy, as well as for basic, negotiate and digest authentications.

This provides an unified interface for all authentication handlers (urllib2 provides far too many with different policies).

The interaction between this handler and the urllib2 framework is not obvious, it works as follow:

opener.open(request) is called:

Method __init__ Undocumented
Method update_auth Update a value in auth marking the auth as modified if needed
Method auth_required Retry the request if the auth scheme is ours.
Method add_auth_header Add the authentication header to the request
Method auth_match Check that we are able to handle that authentication scheme.
Method build_auth_header Build the value of the header used to authenticate.
Method auth_successful The authentification was successful for the request.
Method get_user_password Ask user for a password if none is already available.
Method http_request Insert an authentication header if information is available
Method _parse_auth_header Parse the authentication header.
Method _build_password_prompt Build a prompt taking the protocol used into account.
Method _build_username_prompt Build a prompt taking the protocol used into account.
def __init__(self):
Undocumented
def _parse_auth_header(self, server_header):
Parse the authentication header.
Parametersserver_headerThe value of the header sent by the server describing the authenticaion request.
ReturnsA tuple (scheme, remainder) scheme being the first word in the given header (lower cased), remainder may be None.
def update_auth(self, auth, key, value):
Update a value in auth marking the auth as modified if needed
def auth_required(self, request, headers):
Retry the request if the auth scheme is ours.
ParametersrequestThe request needing authentication.
headersThe headers for the authentication error response.
ReturnsNone or the response for the authenticated request.
def add_auth_header(self, request, header):
Add the authentication header to the request
def auth_match(self, header, auth):
Check that we are able to handle that authentication scheme.

The request authentication parameters may need to be updated with info from the server. Some of these parameters, when combined, are considered to be the authentication key, if one of them change the authentication result may change. 'user' and 'password' are exampls, but some auth schemes may have others (digest's nonce is an example, digest's nonce_count is a counter-example). Such parameters must be updated by using the update_auth() method.

ParametersheaderThe authentication header sent by the server.
authThe auth parameters already known. They may be updated.
ReturnsTrue if we can try to handle the authentication.
def build_auth_header(self, auth, request):
Build the value of the header used to authenticate.
ParametersauthThe auth parameters needed to build the header.
requestThe request needing authentication.
ReturnsNone or header.
def auth_successful(self, request, response):
The authentification was successful for the request.

Additional infos may be available in the response.

ParametersrequestThe succesfully authenticated request.
responseThe server response (may contain auth info).
def get_user_password(self, auth):
Ask user for a password if none is already available.
Parametersauthauthentication info gathered so far (from the initial url and then during dialog with the server).
def _build_password_prompt(self, auth):
Build a prompt taking the protocol used into account.

The AuthHandler is used by http and https, we want that information in the prompt, so we build the prompt from the authentication dict which contains all the needed parts.

Also, http and proxy AuthHandlers present different prompts to the user. The daughter classes should implements a public build_password_prompt using this method.

def _build_username_prompt(self, auth):
Build a prompt taking the protocol used into account.

The AuthHandler is used by http and https, we want that information in the prompt, so we build the prompt from the authentication dict which contains all the needed parts.

Also, http and proxy AuthHandlers present different prompts to the user. The daughter classes should implements a public build_username_prompt using this method.

def http_request(self, request):
Insert an authentication header if information is available
API Documentation for Bazaar, generated by pydoctor at 2022-06-16 00:25:16.