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