paste.auth.form – HTML form/cookie authentication¶
Authentication via HTML Form
This is a very simple HTML form login screen that asks for the username
and password. This middleware component requires that an authorization
function taking the name and passsword and that it be placed in your
application stack. This class does not include any session management
code or way to save the user’s authorization; however, it is easy enough
to put paste.auth.cookie in your application stack.
>>> from paste.wsgilib import dump_environ
>>> from paste.httpserver import serve
>>> from paste.auth.cookie import AuthCookieHandler
>>> from paste.auth.form import AuthFormHandler
>>> def authfunc(environ, username, password):
... return username == password
>>> serve(AuthCookieHandler(
... AuthFormHandler(dump_environ, authfunc)))
serving on...
Module Contents¶
- class paste.auth.form.AuthFormHandler(application, authfunc, template=None)¶
HTML-based login middleware
This causes a HTML form to be returned if
REMOTE_USERis not found in theenviron. If the form is returned, theusernameandpasswordcombination are given to a user-supplied authentication function,authfunc. If this is successful, then application processing continues.Parameters:
applicationThe application object is called only upon successful authentication, and can assume
environ['REMOTE_USER']is set. If theREMOTE_USERis already set, this middleware is simply pass-through.authfuncThis is a mandatory user-defined function which takes a
environ,usernameandpasswordfor its first three arguments. It should returnTrueif the user is authenticated.templateThis is an optional (a default is provided) HTML fragment that takes exactly one
%ssubstution argument; which must be used for the form’sactionto ensure that this middleware component does not alter the current path. The HTML form must usePOSTand have two input names:usernameandpassword.Since the authentication form is submitted (via
POST) neither thePATH_INFOnor theQUERY_STRINGare accessed, and hence the current path remains _unaltered_ through the entire authentication process. If authentication succeeds, theREQUEST_METHODis converted from aPOSTto aGET, so that a redirect is unnecessary (unlike most form auth implementations)
- paste.auth.form.make_form(app, global_conf, realm, authfunc, **kw)¶
Grant access via form authentication
Config looks like this:
[filter:grant] use = egg:Paste#auth_form realm=myrealm authfunc=somepackage.somemodule:somefunction