Attention

You are looking at outdated documentation for version 1.x. A newer version is available.

5.5.3.1.8. wsgidav.http_authenticator

WSGI middleware for HTTP basic and digest authentication.

Usage:

from http_authenticator import HTTPAuthenticator

WSGIApp = HTTPAuthenticator(ProtectedWSGIApp, domain_controller, acceptbasic,
                            acceptdigest, defaultdigest)

where:
  ProtectedWSGIApp is the application requiring authenticated access
  
  domain_controller is a domain controller object meeting specific 
  requirements (below)
  
  acceptbasic is a boolean indicating whether to accept requests using
  the basic authentication scheme (default = True)
  
  acceptdigest is a boolean indicating whether to accept requests using
  the digest authentication scheme (default = True)
  
  defaultdigest is a boolean. if True, an unauthenticated request will 
  be sent a digest authentication required response, else the unauthenticated 
  request will be sent a basic authentication required response 
  (default = True)

The HTTPAuthenticator will put the following authenticated information in the environ dictionary:

environ["http_authenticator.realm"] = realm name
environ["http_authenticator.username"] = username

Domain Controllers

The HTTP basic and digest authentication schemes are based on the following concept:

Each requested relative URI can be resolved to a realm for authentication, for example: /fac_eng/courses/ee5903/timetable.pdf -> might resolve to realm ‘Engineering General’ /fac_eng/examsolns/ee5903/thisyearssolns.pdf -> might resolve to realm ‘Engineering Lecturers’ /med_sci/courses/m500/surgery.htm -> might resolve to realm ‘Medical Sciences General’ and each realm would have a set of username and password pairs that would allow access to the resource.

A domain controller provides this information to the HTTPAuthenticator. This allows developers to write their own domain controllers, that might, for example, interface with their own user database.

for simple applications, a SimpleDomainController is provided that will take in a single realm name (for display) and a single dictionary of username (key) and password (value) string pairs

Usage:

from http_authenticator import SimpleDomainController
users = dict(({'John Smith': 'YouNeverGuessMe', 'Dan Brown': 'DontGuessMeEither'})
realm = 'Sample Realm'
domain_controller = SimpleDomainController(users, realm)

Domain Controllers must provide the methods as described in wsgidav.interfaces.domaincontrollerinterface (interface)

The environ variable here is the WSGI ‘environ’ dictionary. It is passed to all methods of the domain controller as a means for developers to pass information from previous middleware or server config (if required).

See Developers info for more information about the WsgiDAV architecture.

Functions

md5 Returns a md5 hash object; optionally initialized with a string

Classes

HTTPAuthenticator(application, config) WSGI Middleware for basic and digest authenticator.
SimpleDomainController([dictusers, realmname]) SimpleDomainController : Simple domain controller for HTTPAuthenticator.