# HG changeset patch # User paulb # Date 1195868328 0 # Node ID bd9b5311c2e6cb8729f2768f0a8a8b93401c6374 # Parent 406c86bad317d8b7879c611b1975967ec41e440a [project @ 2007-11-24 01:38:44 by paulb] Made distinct packages for the OpenIDLogin and SimpleWithOpenID examples. diff -r 406c86bad317 -r bd9b5311c2e6 examples/BaseHTTPRequestHandler/OpenIDLoginApp.py --- a/examples/BaseHTTPRequestHandler/OpenIDLoginApp.py Mon Nov 19 00:23:50 2007 +0000 +++ b/examples/BaseHTTPRequestHandler/OpenIDLoginApp.py Sat Nov 24 01:38:48 2007 +0000 @@ -1,59 +1,12 @@ #!/usr/bin/env python from WebStack.Adapters.BaseHTTPRequestHandler import deploy -from WebStack.Resources.OpenIDLogin import OpenIDLoginResource, Authenticator -from WebStack.Resources.ResourceMap import MapResource -from WebStack.Resources.Static import StringResource -from WebStack.Generic import ContentType +from OpenIDLogin import get_site_map app_url = "http://localhost:8081" # No trailing "/"! +resource = get_site_map(app_url) print "Serving..." -deploy( - MapResource({ - "login" : - OpenIDLoginResource( - app_url=app_url, - authenticator=Authenticator( - credentials=( - # Local identifier, username, password - ((app_url + "/badger", "badger"), "abc"), - ((app_url + "/vole", "vole"), "xyz"), - ) - ) - ), - - # Some local OpenID pages. - - "badger" : - StringResource(""" - - - - - Badger's Home Page - - -

Home page for the OpenID authenticated user, badger.

- - - """ % (app_url, app_url), ContentType("text/html")), - "vole" : - StringResource(""" - - - - - Vole's Home Page - - -

Home page for the OpenID authenticated user, vole.

- - - """ % (app_url, app_url), ContentType("text/html")) - }), - address=("", 8081), - handle_errors=0 -) +deploy(resource, address=("", 8081), handle_errors=0) # vim: tabstop=4 expandtab shiftwidth=4 diff -r 406c86bad317 -r bd9b5311c2e6 examples/BaseHTTPRequestHandler/SimpleWithOpenIDApp.py --- a/examples/BaseHTTPRequestHandler/SimpleWithOpenIDApp.py Mon Nov 19 00:23:50 2007 +0000 +++ b/examples/BaseHTTPRequestHandler/SimpleWithOpenIDApp.py Sat Nov 24 01:38:48 2007 +0000 @@ -1,36 +1,15 @@ #!/usr/bin/env python from WebStack.Adapters.BaseHTTPRequestHandler import deploy -from WebStack.Resources.OpenIDRedirect import OpenIDRedirectResource, OpenIDRedirectAuthenticator -from WebStack.Resources.OpenIDInitiation import OpenIDInitiationResource -from WebStack.Resources.ResourceMap import MapResource -from Simple import SimpleResource +from SimpleWithOpenID import get_site_map app_url = "http://localhost:8080" # No trailing "/"! initiation_url = "http://localhost:8080/login" secret_key = "horses" # Must match the login authenticator's key. +resource = get_site_map(app_url, initiation_url, secret_key) + print "Serving..." -deploy( - MapResource({ - "simple" : - OpenIDRedirectResource( - login_url=initiation_url, - app_url=app_url, - resource=SimpleResource(), - authenticator=OpenIDRedirectAuthenticator( - secret_key=secret_key, - app_url=app_url - ), - anonymous_parameter_name="anonymous", - logout_parameter_name="logout" - ), - - # The "login" is really OpenID initiation. - - "login" : OpenIDInitiationResource() - }), - handle_errors=0 -) +deploy(resource, handle_errors=0) # vim: tabstop=4 expandtab shiftwidth=4 diff -r 406c86bad317 -r bd9b5311c2e6 examples/Common/OpenIDLogin/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/Common/OpenIDLogin/__init__.py Sat Nov 24 01:38:48 2007 +0000 @@ -0,0 +1,57 @@ +#!/usr/bin/env python + +"An OpenID login example with some local user pages." + +from WebStack.Resources.OpenIDLogin import OpenIDLoginResource, Authenticator +from WebStack.Resources.ResourceMap import MapResource +from WebStack.Resources.Static import StringResource +from WebStack.Generic import ContentType + +def get_site_map(app_url): + + "Return a resource for the site having the given 'app_url'." + + return MapResource({ + "login" : + OpenIDLoginResource( + app_url=app_url, + authenticator=Authenticator( + credentials=( + # Local identifier, username, password + ((app_url + "/badger", "badger"), "abc"), + ((app_url + "/vole", "vole"), "xyz"), + ) + ) + ), + + # Some local OpenID pages. + + "badger" : + StringResource(""" + + + + + Badger's Home Page + + +

Home page for the OpenID authenticated user, badger.

+ + + """ % (app_url, app_url), ContentType("text/html")), + "vole" : + StringResource(""" + + + + + Vole's Home Page + + +

Home page for the OpenID authenticated user, vole.

+ + + """ % (app_url, app_url), ContentType("text/html")) + }) + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r 406c86bad317 -r bd9b5311c2e6 examples/Common/SimpleWithOpenID/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/Common/SimpleWithOpenID/__init__.py Sat Nov 24 01:38:48 2007 +0000 @@ -0,0 +1,52 @@ +#!/usr/bin/env python + +from WebStack.Generic import ContentType +from WebStack.Resources.OpenIDRedirect import OpenIDRedirectResource, OpenIDRedirectAuthenticator +from WebStack.Resources.OpenIDInitiation import OpenIDInitiationResource +from WebStack.Resources.ResourceMap import MapResource +from WebStack.Resources.Static import StringResource +from Simple import SimpleResource + +def get_site_map(app_url, initiation_url, secret_key): + + """ + Resource a resource for the site having the given 'app_url', using the given + 'initiation_url' for the OpenID initiation page, and the specified + 'secret_key' for authentication tokens. + """ + + return MapResource({ + "simple" : + OpenIDRedirectResource( + login_url=initiation_url, + app_url=app_url, + resource=SimpleResource(), + authenticator=OpenIDRedirectAuthenticator( + secret_key=secret_key, + app_url=app_url + ), + anonymous_parameter_name="anonymous", + logout_parameter_name="logout" + ), + + # The "login" is really OpenID initiation. + + "login" : OpenIDInitiationResource(), + + # A root page. + + "" : + StringResource(""" + + + Simple Application with OpenID Login + + +

Access the application here.

+ + + """, ContentType("text/html")) + + }) + +# vim: tabstop=4 expandtab shiftwidth=4