WSGI middleware for HTTP basic and digest authentication.


from http_authenticator import HTTPAuthenticator

WSGIApp = HTTPAuthenticator(ProtectedWSGIApp, domain_controller, accept_basic,
                            accept_digest, default_to_digest)

  ProtectedWSGIApp is the application requiring authenticated access

  domain_controller is a domain controller object meeting specific
  requirements (below)

  accept_basic is a boolean indicating whether to accept requests using
  the basic authentication scheme (default = True)

  accept_digest is a boolean indicating whether to accept requests using
  the digest authentication scheme (default = True)

  default_to_digest 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["wsgidav.auth.realm"] = realm name
environ["wsgidav.auth.user_name"] = user_name
environ["wsgidav.auth.roles"] = <tuple> (optional)
environ["wsgidav.auth.permissions"] = <tuple> (optional)

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 user_name 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 user_name (key) and password (value) string pairs


from wsgidav.dc.simple_dc 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).


HTTPAuthenticator(wsgidav_app, next_app, config)

WSGI Middleware for basic and digest authentication.


make_domain_controller(wsgidav_app, config)

Other Members


int([x]) -> integer int(x, base=10) -> integer