# HG changeset patch # User paulb # Date 1194828718 0 # Node ID fd071f4c6c32d251327c33d532a2bc243db7f71b # Parent 26865b172666db0d755f07e22cea55ff086e36d9 [project @ 2007-11-12 00:51:47 by paulb] Added an example of OpenID authentication. diff -r 26865b172666 -r fd071f4c6c32 examples/BaseHTTPRequestHandler/OpenIDLoginApp.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/BaseHTTPRequestHandler/OpenIDLoginApp.py Mon Nov 12 00:51:58 2007 +0000 @@ -0,0 +1,59 @@ +#!/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 + +app_url = "http://localhost:8081" # No trailing "/"! + +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 +) + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r 26865b172666 -r fd071f4c6c32 examples/BaseHTTPRequestHandler/SimpleWithOpenIDApp.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/BaseHTTPRequestHandler/SimpleWithOpenIDApp.py Mon Nov 12 00:51:58 2007 +0000 @@ -0,0 +1,37 @@ +#!/usr/bin/env python + +from WebStack.Adapters.BaseHTTPRequestHandler import deploy +from WebStack.Resources.LoginRedirect import LoginRedirectResource +from WebStack.Resources.OpenIDRedirect import OpenIDRedirectAuthenticator +from WebStack.Resources.OpenIDInitiation import OpenIDInitiationResource +from WebStack.Resources.ResourceMap import MapResource +from Simple import SimpleResource + +app_url = "http://localhost:8080" # No trailing "/"! +initiation_url = "http://localhost:8080/login" +secret_key = "horses" # Must match the login authenticator's key. + +print "Serving..." +deploy( + MapResource({ + "simple" : + LoginRedirectResource( + 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 +) + +# vim: tabstop=4 expandtab shiftwidth=4