Attention

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

wsgidav.http_authenticator

Description

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).

Classes

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

Other Members

BaseMiddleware(application, config) Abstract base middleware class.
HOTFIX_WINXP_AcceptRootShareLogin bool(x) -> bool
HOTFIX_WIN_AcceptAnonymousOptions bool(x) -> bool
WsgiDAVDomainController(userMap)
calc_base64(s) Return base64 encoded binarystring.
calc_hexdigest(s) Return md5 digest for a string.
compat Tool functions to support Python 2 and 3.
md5 Returns a md5 hash object; optionally initialized with a string
random Random variable generators.
re Support for regular expressions (RE).
time This module provides various functions to manipulate time values.
util Miscellaneous support functions for WsgiDAV.