paulb@648 | 1 | #!/usr/bin/env python |
paulb@652 | 2 | # -*- coding: iso-8859-1 -*- |
paulb@648 | 3 | |
paulb@648 | 4 | "An OpenID login provider." |
paulb@648 | 5 | |
paulb@648 | 6 | # Site map imports. |
paulb@648 | 7 | |
paulb@648 | 8 | from WebStack.Generic import ContentType |
paulb@648 | 9 | from WebStack.Resources.OpenIDLogin import Authenticator |
paulb@648 | 10 | from WebStack.Resources.ResourceMap import MapResource |
paulb@648 | 11 | from WebStack.Resources.Selectors import EncodingSelector, PathSelector |
paulb@648 | 12 | from WebStack.Resources.Static import StringResource |
paulb@648 | 13 | import XSLForms.Resources.OpenIDLogin |
paulb@648 | 14 | from XSLForms.Resources.WebResources import output, prepare_resources as pr, resources |
paulb@648 | 15 | |
paulb@648 | 16 | # Configuration settings. |
paulb@648 | 17 | |
paulb@648 | 18 | encoding = "utf-8" |
paulb@648 | 19 | |
paulb@648 | 20 | # Resource classes. |
paulb@648 | 21 | |
paulb@648 | 22 | class LoginResource(XSLForms.Resources.OpenIDLogin.OpenIDLoginResource): |
paulb@648 | 23 | |
paulb@648 | 24 | "Special login screen for this application." |
paulb@648 | 25 | |
paulb@648 | 26 | resource_dir = resources(__file__) |
paulb@648 | 27 | template_resources = { |
paulb@648 | 28 | "login" : output("login_template.xhtml"), |
paulb@648 | 29 | "success" : output("success_template.xhtml") |
paulb@648 | 30 | } |
paulb@648 | 31 | |
paulb@648 | 32 | # Site map initialisation. |
paulb@648 | 33 | |
paulb@648 | 34 | def get_site(host, use_redirect=1): |
paulb@648 | 35 | |
paulb@648 | 36 | "Return a simple Web site resource." |
paulb@648 | 37 | |
paulb@648 | 38 | # Authentication objects. |
paulb@648 | 39 | |
paulb@648 | 40 | credentials = [ |
paulb@648 | 41 | ((host + "/badger", "badger"), "abc"), |
paulb@652 | 42 | ((host + "/vole", "vole"), "xyz"), |
paulb@652 | 43 | ((host + u"/???", u"???"), u"???") |
paulb@648 | 44 | ] |
paulb@648 | 45 | login_authenticator = Authenticator(credentials) |
paulb@648 | 46 | |
paulb@648 | 47 | # Get a login resource. |
paulb@648 | 48 | |
paulb@648 | 49 | login_resource = LoginResource(host, login_authenticator, use_redirect=use_redirect) |
paulb@648 | 50 | |
paulb@648 | 51 | # A container for the login resource and user pages. |
paulb@648 | 52 | |
paulb@648 | 53 | resource = MapResource({ |
paulb@648 | 54 | "login" : login_resource, |
paulb@648 | 55 | |
paulb@648 | 56 | # Some local OpenID pages. |
paulb@648 | 57 | |
paulb@648 | 58 | "badger" : |
paulb@648 | 59 | StringResource(""" |
paulb@648 | 60 | <html> |
paulb@648 | 61 | <head> |
paulb@648 | 62 | <link rel="openid2.provider openid.server" href="%s/login" /> |
paulb@648 | 63 | <link rel="openid2.local_id openid.delegate" href="%s/badger" /> |
paulb@648 | 64 | <title>Badger's Home Page</title> |
paulb@648 | 65 | </head> |
paulb@648 | 66 | <body> |
paulb@648 | 67 | <p>Home page for the OpenID authenticated user, <code>badger</code>.</p> |
paulb@648 | 68 | </body> |
paulb@648 | 69 | </html> |
paulb@648 | 70 | """ % (host, host), ContentType("text/html")), |
paulb@652 | 71 | u"???" : |
paulb@652 | 72 | StringResource(u""" |
paulb@652 | 73 | <html> |
paulb@652 | 74 | <head> |
paulb@652 | 75 | <link rel="openid2.provider openid.server" href="%s/login" /> |
paulb@652 | 76 | <link rel="openid2.local_id openid.delegate" href="%s/???" /> |
paulb@652 | 77 | <title>Home Page for ???</title> |
paulb@652 | 78 | </head> |
paulb@652 | 79 | <body> |
paulb@652 | 80 | <p>Home page for the OpenID authenticated user, <code>???</code>.</p> |
paulb@652 | 81 | </body> |
paulb@652 | 82 | </html> |
paulb@652 | 83 | """ % (host, host), ContentType("text/html", "iso-8859-1")), |
paulb@648 | 84 | "vole" : |
paulb@648 | 85 | StringResource(""" |
paulb@648 | 86 | <html> |
paulb@648 | 87 | <head> |
paulb@648 | 88 | <link rel="openid2.provider openid.server" href="%s/login" /> |
paulb@648 | 89 | <link rel="openid2.local_id openid.delegate" href="%s/vole" /> |
paulb@648 | 90 | <title>Vole's Home Page</title> |
paulb@648 | 91 | </head> |
paulb@648 | 92 | <body> |
paulb@648 | 93 | <p>Home page for the OpenID authenticated user, <code>vole</code>.</p> |
paulb@648 | 94 | </body> |
paulb@648 | 95 | </html> |
paulb@648 | 96 | """ % (host, host), ContentType("text/html")) |
paulb@648 | 97 | }) |
paulb@648 | 98 | |
paulb@648 | 99 | # Wrap the resource up with information about the application root. |
paulb@648 | 100 | |
paulb@648 | 101 | return EncodingSelector(PathSelector(resource), encoding) |
paulb@648 | 102 | |
paulb@648 | 103 | # Resource preparation ahead of time - useful for making installations. |
paulb@648 | 104 | |
paulb@648 | 105 | def prepare_resources(): |
paulb@648 | 106 | for cls in [LoginResource]: |
paulb@648 | 107 | pr(cls) |
paulb@648 | 108 | |
paulb@648 | 109 | # vim: tabstop=4 expandtab shiftwidth=4 |