1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/XSLForms/Resources/OpenIDRedirect.py Sun Feb 03 20:04:44 2008 +0000
1.3 @@ -0,0 +1,59 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +"""
1.7 +OpenID redirection resources for XSLForms applications. These resources use
1.8 +"root" attributes on transaction objects, and therefore should be defined within
1.9 +the appropriate resources in site maps.
1.10 +
1.11 +Copyright (C) 2006, 2007, 2008 Paul Boddie <paul@boddie.org.uk>
1.12 +
1.13 +This program is free software; you can redistribute it and/or modify it under
1.14 +the terms of the GNU Lesser General Public License as published by the Free
1.15 +Software Foundation; either version 3 of the License, or (at your option) any
1.16 +later version.
1.17 +
1.18 +This program is distributed in the hope that it will be useful, but WITHOUT
1.19 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.20 +FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
1.21 +details.
1.22 +
1.23 +You should have received a copy of the GNU Lesser General Public License along
1.24 +with this program. If not, see <http://www.gnu.org/licenses/>.
1.25 +"""
1.26 +
1.27 +import WebStack.Resources.OpenIDRedirect # OpenIDRedirectResource
1.28 +
1.29 +OpenIDRedirectAuthenticator = WebStack.Resources.OpenIDRedirect.OpenIDRedirectAuthenticator
1.30 +
1.31 +class OpenIDRedirectResource(WebStack.Resources.OpenIDRedirect.OpenIDRedirectResource):
1.32 +
1.33 + "A redirect resource which uses dynamic knowledge about the URL space."
1.34 +
1.35 + def __init__(self, host, path_to_login, *args, **kw):
1.36 +
1.37 + """
1.38 + Initialise the resource with the 'host', 'path_to_login' (the path from
1.39 + the root of the application to the login screen), and other
1.40 + LoginRedirectResource details.
1.41 +
1.42 + To get the root of the application, this resource needs an attribute on
1.43 + the transaction called "root".
1.44 +
1.45 + Examples of 'path_to_login' with "root" attribute and result:
1.46 +
1.47 + "login", "/" -> "/login"
1.48 + "login", "/app/" -> "/app/login"
1.49 + "app/login", "/" -> "/app/login"
1.50 + """
1.51 +
1.52 + self.host = host
1.53 + self.path_to_login = path_to_login
1.54 + WebStack.Resources.OpenIDRedirect.OpenIDRedirectResource.__init__(self, *args, **kw)
1.55 +
1.56 + def get_app_url(self, trans):
1.57 + return self.host
1.58 +
1.59 + def get_login_url(self, trans):
1.60 + return self.host + trans.get_attributes()["root"] + self.path_to_login
1.61 +
1.62 +# vim: tabstop=4 expandtab shiftwidth=4