Redirect

Skip to end of metadata
Go to start of metadata

Redirect

The redirect method is very similar to the Forward method except that rather than internally forwarding the request to some URL below the root URL for that WSGI application so that the page displayed appears to be at the same URL as the request, the redirect method performs an external HTTP redirect which redirects the browser to the appropriate URL for the user to sign in.

Here's an example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
from authkit.authenticate import middleware, sample_app

app = middleware(
    sample_app,
    setup_method='redirect,cookie',
    redirect_url='http://3aims.com',
    cookie_secret='asdasd'
)
if __name__ == '__main__':
    from paste.httpserver import serve
    serve(app, host='0.0.0.0', port=8080)

If a permission check failed the browser would be redirected to http://3aims.com where presumably there would be a sign in form (although this isn't currently the case). The sign in should then set a cookie so that next time the user visits a page, the ``cookie`` middleware which is also setup will read the username from the cookie.

One of the drawbacks of using the redirect approach is that the cookie which is set at the page which is redirected to, must be in a format readable by the cookie middleware.
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.