close Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Version 6 (modified by cmlenz, 16 years ago) (diff)

--

Framework for Authentication and Authorization

This page describes an experimental branch that adds a simple generic auth framework to Diva.

The main goals of this framework are:

  • Enable relatively easy switching between HTTP authentication (such as Basic or Digest authentication performed by the web server) and form-based authentication.
  • Provide basic primitives to get started with form-based login, while allowing complete customization.
  • Provide convenience functions for checking authorization to perform certain actions.
  • No reliance on a specific backend storage for user profiles and credentials.
  • No restriction to a specific method of controlling access to resources (such as ACLs). Applications can use whatever access control granularity they need.
  • Storage-independent generation and verification of authentication cookies for form-based login.

Possible/peripheral goals:

  • Utility functions for generating and verifying encrypted passwords.
  • WSGI middleware for using HTTP authentication, primarily in the context of the DevelopmentServer

All of the above is implemented on the branch at this point.

Non-goals include:

  • Built-in processes and UI for user registration, activation, password resetting, and other high-level features.

High-Level Architecture Stuff

Application Mixin Approach

The current branch defines an AuthMixIn class that auth-enabled applications are supposed to subclass. It adds a couple of method stubs to the Application class, and contributes a request filter that performs authentication.

Filters Refactoring

Due to the way application mix-in classes can contribute filters, ordering request filters explicitly becomes too painful. The branch enhances the way request filters are defined by allowing them to declare the abstract service they provide (such as "localization" or "error-handling"), and also declare what services they rely on to do their job. For example:

@filters.register('form-processing', requires=['templating', 'localization'])
def form_filter(request, response, chain):
    ...

The ordering of request filters is then inferred from this dependency information.

Authentication Methods

HTTP Authentication

Form-based Authentication

Hybrid HTTP/Cookies-based Authentication

This mode allows the use of HTTP authentication without having to protect the entire URL namespace. Only one or more sub-resources (such as /login) are protected by HTTP authentication. When the user visits a protected URL, Diva sets a cookie (in the same manner as with form-based authentication), thereby enabling resources outside of the protected area to identify the user and apply her permissions.