source: TI12-security/trunk/python/Tests/openid-provider/op/op/config/middleware.py @ 4081

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/python/Tests/openid-provider/op/op/config/middleware.py@4081
Revision 4081, 2.3 KB checked in by pjkersha, 11 years ago (diff)

First working version of an OpenID Provider as opposed to a Relying Party as avail. with AuthKit?. The code is taken from the HTTPServer example in the Python OpenID package and refactored into WSGI middleware.

  • ndg.security.server.wsgi.openid_provider - WSGI middleware package
  • Tests/openid-provider/op: pylons project test harness for the above

TODO: integrate into AuthKit? and Beaker Session Middleware as required.

Line 
1"""Pylons middleware initialization"""
2from paste.cascade import Cascade
3from paste.registry import RegistryManager
4from paste.urlparser import StaticURLParser
5from paste.deploy.converters import asbool
6
7from pylons import config
8from pylons.error import error_template
9from pylons.middleware import error_mapper, ErrorDocuments, ErrorHandler, \
10    StaticJavascripts
11from pylons.wsgiapp import PylonsApp
12
13from op.config.environment import load_environment
14
15from ndg.security.server.wsgi.openid_provider import OpenIDProviderMiddleware
16from beaker.middleware import SessionMiddleware
17
18def make_app(global_conf, full_stack=True, **app_conf):
19    """Create a Pylons WSGI application and return it
20
21    ``global_conf``
22        The inherited configuration for this application. Normally from
23        the [DEFAULT] section of the Paste ini file.
24
25    ``full_stack``
26        Whether or not this application provides a full WSGI stack (by
27        default, meaning it handles its own exceptions and errors).
28        Disable full_stack when this application is "managed" by
29        another WSGI middleware.
30
31    ``app_conf``
32        The application's local configuration. Normally specified in the
33        [app:<name>] section of the Paste ini file (where <name>
34        defaults to main).
35    """
36    # Configure the Pylons environment
37    load_environment(global_conf, app_conf)
38
39    # The Pylons WSGI app
40    app = PylonsApp()
41
42    # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares)
43    app = OpenIDProviderMiddleware(app, base_url='http://localhost:8700')
44    app = SessionMiddleware(
45        app, 
46        key='authkit.open_id', 
47        secret='some secret',
48    )
49   
50    if asbool(full_stack):
51        # Handle Python exceptions
52        app = ErrorHandler(app, global_conf, error_template=error_template,
53                           **config['pylons.errorware'])
54
55        # Display error documents for 401, 403, 404 status codes (and
56        # 500 when debug is disabled)
57        app = ErrorDocuments(app, global_conf, mapper=error_mapper, **app_conf)
58
59    # Establish the Registry for this application
60    app = RegistryManager(app)
61
62    # Static files
63    javascripts_app = StaticJavascripts()
64    static_app = StaticURLParser(config['pylons.paths']['static_files'])
65    app = Cascade([static_app, javascripts_app, app])
66    return app
Note: See TracBrowser for help on using the repository browser.