1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/examples/BaseHTTPRequestHandler/OpenIDLoginApp.py Mon Nov 12 00:51:58 2007 +0000
1.3 @@ -0,0 +1,59 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +from WebStack.Adapters.BaseHTTPRequestHandler import deploy
1.7 +from WebStack.Resources.OpenIDLogin import OpenIDLoginResource, Authenticator
1.8 +from WebStack.Resources.ResourceMap import MapResource
1.9 +from WebStack.Resources.Static import StringResource
1.10 +from WebStack.Generic import ContentType
1.11 +
1.12 +app_url = "http://localhost:8081" # No trailing "/"!
1.13 +
1.14 +print "Serving..."
1.15 +deploy(
1.16 + MapResource({
1.17 + "login" :
1.18 + OpenIDLoginResource(
1.19 + app_url=app_url,
1.20 + authenticator=Authenticator(
1.21 + credentials=(
1.22 + # Local identifier, username, password
1.23 + ((app_url + "/badger", "badger"), "abc"),
1.24 + ((app_url + "/vole", "vole"), "xyz"),
1.25 + )
1.26 + )
1.27 + ),
1.28 +
1.29 + # Some local OpenID pages.
1.30 +
1.31 + "badger" :
1.32 + StringResource("""
1.33 + <html>
1.34 + <head>
1.35 + <link rel="openid2.provider openid.server" href="%s/login" />
1.36 + <link rel="openid2.local_id openid.delegate" href="%s/badger" />
1.37 + <title>Badger's Home Page</title>
1.38 + </head>
1.39 + <body>
1.40 + <p>Home page for the OpenID authenticated user, <code>badger</code>.</p>
1.41 + </body>
1.42 + </html>
1.43 + """ % (app_url, app_url), ContentType("text/html")),
1.44 + "vole" :
1.45 + StringResource("""
1.46 + <html>
1.47 + <head>
1.48 + <link rel="openid2.provider openid.server" href="%s/login" />
1.49 + <link rel="openid2.local_id openid.delegate" href="%s/vole" />
1.50 + <title>Vole's Home Page</title>
1.51 + </head>
1.52 + <body>
1.53 + <p>Home page for the OpenID authenticated user, <code>vole</code>.</p>
1.54 + </body>
1.55 + </html>
1.56 + """ % (app_url, app_url), ContentType("text/html"))
1.57 + }),
1.58 + address=("", 8081),
1.59 + handle_errors=0
1.60 +)
1.61 +
1.62 +# vim: tabstop=4 expandtab shiftwidth=4
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/examples/BaseHTTPRequestHandler/SimpleWithOpenIDApp.py Mon Nov 12 00:51:58 2007 +0000
2.3 @@ -0,0 +1,37 @@
2.4 +#!/usr/bin/env python
2.5 +
2.6 +from WebStack.Adapters.BaseHTTPRequestHandler import deploy
2.7 +from WebStack.Resources.LoginRedirect import LoginRedirectResource
2.8 +from WebStack.Resources.OpenIDRedirect import OpenIDRedirectAuthenticator
2.9 +from WebStack.Resources.OpenIDInitiation import OpenIDInitiationResource
2.10 +from WebStack.Resources.ResourceMap import MapResource
2.11 +from Simple import SimpleResource
2.12 +
2.13 +app_url = "http://localhost:8080" # No trailing "/"!
2.14 +initiation_url = "http://localhost:8080/login"
2.15 +secret_key = "horses" # Must match the login authenticator's key.
2.16 +
2.17 +print "Serving..."
2.18 +deploy(
2.19 + MapResource({
2.20 + "simple" :
2.21 + LoginRedirectResource(
2.22 + login_url=initiation_url,
2.23 + app_url=app_url,
2.24 + resource=SimpleResource(),
2.25 + authenticator=OpenIDRedirectAuthenticator(
2.26 + secret_key=secret_key,
2.27 + app_url=app_url
2.28 + ),
2.29 + anonymous_parameter_name="anonymous",
2.30 + logout_parameter_name="logout"
2.31 + ),
2.32 +
2.33 + # The "login" is really OpenID initiation.
2.34 +
2.35 + "login" : OpenIDInitiationResource()
2.36 + }),
2.37 + handle_errors=0
2.38 +)
2.39 +
2.40 +# vim: tabstop=4 expandtab shiftwidth=4