Dashboard > AuthKit Cookbook > ... > AuthKit Authentication Methods > Redirect
  AuthKit Cookbook Log In | Sign Up   View a printable version of the current page.  
  Redirect
Added by James Gardner, last edited by James Gardner on Apr 16, 2007
Labels: 
(None)

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.

Site running on a free Atlassian Confluence Open Source Project License granted to Pylons. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.3.3 Build:#645 Feb 13, 2007) - Bug/feature request - Contact Administrators