paulb@744 | 1 | #!/usr/bin/env python |
paulb@757 | 2 | # -*- coding: iso-8859-1 -*- |
paulb@744 | 3 | |
paulb@744 | 4 | "An OpenID login example with some local user pages." |
paulb@744 | 5 | |
paulb@744 | 6 | from WebStack.Resources.OpenIDLogin import OpenIDLoginResource, Authenticator |
paulb@744 | 7 | from WebStack.Resources.ResourceMap import MapResource |
paulb@744 | 8 | from WebStack.Resources.Static import StringResource |
paulb@744 | 9 | from WebStack.Generic import ContentType |
paulb@744 | 10 | |
paulb@763 | 11 | def get_site_map(app_url, deployment_url): |
paulb@763 | 12 | |
paulb@763 | 13 | """ |
paulb@763 | 14 | Return a resource for the site having the given 'app_url' and |
paulb@763 | 15 | 'deployment_url'. The 'app_url' should be the "bare" reference using a |
paulb@763 | 16 | protocol, host and port, not including any path information. |
paulb@763 | 17 | """ |
paulb@744 | 18 | |
paulb@763 | 19 | login = OpenIDLoginResource( |
paulb@763 | 20 | app_url=app_url, |
paulb@763 | 21 | authenticator=Authenticator( |
paulb@763 | 22 | credentials=( |
paulb@763 | 23 | # Local identifier, username, password |
paulb@763 | 24 | ((deployment_url + "/badger", "badger"), "abc"), |
paulb@763 | 25 | ((deployment_url + "/vole", "vole"), "xyz"), |
paulb@763 | 26 | ((deployment_url + u"/???", u"???"), u"???"), |
paulb@763 | 27 | ) |
paulb@763 | 28 | ) |
paulb@763 | 29 | ) |
paulb@744 | 30 | |
paulb@744 | 31 | return MapResource({ |
paulb@763 | 32 | "" : login, |
paulb@763 | 33 | "login" : login, |
paulb@744 | 34 | |
paulb@744 | 35 | # Some local OpenID pages. |
paulb@744 | 36 | |
paulb@744 | 37 | "badger" : |
paulb@744 | 38 | StringResource(""" |
paulb@744 | 39 | <html> |
paulb@744 | 40 | <head> |
paulb@744 | 41 | <link rel="openid2.provider openid.server" href="%s/login" /> |
paulb@744 | 42 | <link rel="openid2.local_id openid.delegate" href="%s/badger" /> |
paulb@744 | 43 | <title>Badger's Home Page</title> |
paulb@744 | 44 | </head> |
paulb@744 | 45 | <body> |
paulb@744 | 46 | <p>Home page for the OpenID authenticated user, <code>badger</code>.</p> |
paulb@744 | 47 | </body> |
paulb@744 | 48 | </html> |
paulb@763 | 49 | """ % (deployment_url, deployment_url), ContentType("text/html")), |
paulb@757 | 50 | u"???" : |
paulb@757 | 51 | StringResource(u""" |
paulb@757 | 52 | <html> |
paulb@757 | 53 | <head> |
paulb@757 | 54 | <link rel="openid2.provider openid.server" href="%s/login" /> |
paulb@757 | 55 | <link rel="openid2.local_id openid.delegate" href="%s/???" /> |
paulb@757 | 56 | <title>Home Page for ???</title> |
paulb@757 | 57 | </head> |
paulb@757 | 58 | <body> |
paulb@757 | 59 | <p>Home page for the OpenID authenticated user, <code>???</code>.</p> |
paulb@757 | 60 | </body> |
paulb@757 | 61 | </html> |
paulb@763 | 62 | """ % (deployment_url, deployment_url), ContentType("text/html", "iso-8859-1")), |
paulb@744 | 63 | "vole" : |
paulb@744 | 64 | StringResource(""" |
paulb@744 | 65 | <html> |
paulb@744 | 66 | <head> |
paulb@744 | 67 | <link rel="openid2.provider openid.server" href="%s/login" /> |
paulb@744 | 68 | <link rel="openid2.local_id openid.delegate" href="%s/vole" /> |
paulb@744 | 69 | <title>Vole's Home Page</title> |
paulb@744 | 70 | </head> |
paulb@744 | 71 | <body> |
paulb@744 | 72 | <p>Home page for the OpenID authenticated user, <code>vole</code>.</p> |
paulb@744 | 73 | </body> |
paulb@744 | 74 | </html> |
paulb@763 | 75 | """ % (deployment_url, deployment_url), ContentType("text/html")) |
paulb@744 | 76 | }) |
paulb@744 | 77 | |
paulb@744 | 78 | # vim: tabstop=4 expandtab shiftwidth=4 |