File: redirect.py

package info (click to toggle)
python-authkit 0.4.1~r143-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 740 kB
  • ctags: 703
  • sloc: python: 4,643; makefile: 39; sh: 33
file content (31 lines) | stat: -rw-r--r-- 915 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""\
Redirect middleware to redirect the browser to a different URL for sign in
"""
from authkit.authenticate import middleware
from authkit.authenticate.multi import MultiHandler, status_checker

class HandleRedirect(object):
    def __init__(self, app, redirect_to):
        self.app = app
        self.redirect_to = redirect_to

    def __call__(self, environ, start_response):
        start_response('302 Found', [
            ('Location',self.redirect_to),
            ('Content-Type','text/plain'),
            ('Content-Length','0'),
        ])
        return ['redirecting to %s'%self.redirect_to]

def make_redirect_handler(
    app, 
    auth_conf, 
    app_conf=None,
    global_conf=None,
    prefix='authkit.method.redirect.', 
):
    app = MultiHandler(app)
    app.add_method('redirect', HandleRedirect, redirect_to = auth_conf['url'])
    app.add_checker('redirect', status_checker)
    return app