Package wsgitools :: Module middlewares :: Class BasicAuthMiddleware
[hide private]
[frames] | no frames]

Class BasicAuthMiddleware

source code


Middleware implementing HTTP Basic Auth. Upon forwarding the request to the warpped application the environ dictionary is augmented by a REMOTE_USER key.

Instance Methods [hide private]
 
__init__(self, app, check_function, realm='www', app401=None)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
{str: object}
authenticate(self, auth, environ)
Try to authenticate a request.
source code
(str, str)
www_authenticate(self, exception)
Generates a WWW-Authenticate header.
source code
 
authorization_required(self, environ, start_response, exception)
Generate an error page after failed authentication.
source code

Inherited from authentication.AuthenticationMiddleware: __call__

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]
str authorization_method = 'basic'
the implemented Authorization method.
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, app, check_function, realm='www', app401=None)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Parameters:
  • app - is a WSGI application.
  • check_function - is a function taking three arguments username, password and environment returning a bool indicating whether the request may is allowed. The older interface of taking only the first two arguments is still supported via catching a TypeError.
  • app401 - is an optional WSGI application to be used for error messages
  • realm (str)
Overrides: object.__init__

authenticate(self, auth, environ)

source code 

Try to authenticate a request. The Authorization header is examined and checked agains the authorization_method before being passed to this method. This method must either raise an AuthenticationRequired instance or return a dictionary explaining what was successfully authenticated.

Parameters:
  • auth - is the part of the Authorization header after the method
  • environ - is the environment passed with a WSGI request
Returns: {str: object}
a dictionary that provides a key "user" listing the authenticated username as a string. It may also provide the key "outheaders" with a [(str, str)] value to extend the response headers.
Raises:
Overrides: authentication.AuthenticationMiddleware.authenticate
(inherited documentation)

www_authenticate(self, exception)

source code 

Generates a WWW-Authenticate header. Subclasses must implement this method.

Parameters:
  • exception - reason for generating the header
Returns: (str, str)
the header as (part_before_colon, part_after_colon)
Overrides: authentication.AuthenticationMiddleware.www_authenticate
(inherited documentation)

authorization_required(self, environ, start_response, exception)

source code 

Generate an error page after failed authentication. Apart from the exception parameter, this method behaves like a WSGI application.

Parameters:
  • exception - reason for the authentication failure
Overrides: authentication.AuthenticationMiddleware.authorization_required
(inherited documentation)