1 #!/usr/bin/env python 2 # -*- coding: iso-8859-1 -*- 3 4 "An OpenID login example with some local user pages." 5 6 from WebStack.Resources.OpenIDLogin import OpenIDLoginResource, Authenticator 7 from WebStack.Resources.ResourceMap import MapResource 8 from WebStack.Resources.Static import StringResource 9 from WebStack.Generic import ContentType 10 11 def get_site_map(app_url, deployment_url): 12 13 """ 14 Return a resource for the site having the given 'app_url' and 15 'deployment_url'. The 'app_url' should be the "bare" reference using a 16 protocol, host and port, not including any path information. 17 """ 18 19 login = OpenIDLoginResource( 20 app_url=app_url, 21 authenticator=Authenticator( 22 credentials=( 23 # Local identifier, username, password 24 (( "badger", "badger"), "abc"), 25 (( "vole", "vole"), "xyz"), 26 ((u"???", u"???"), u"???"), 27 (( "badger2", "badger"), "abc"), 28 (( "vole2", "vole"), "xyz"), 29 ((u"???2", u"???"), u"???"), 30 ) 31 ) 32 ) 33 34 return MapResource({ 35 "" : login, 36 "login" : login, 37 38 # Some local OpenID pages. 39 40 "badger" : 41 StringResource(""" 42 <html> 43 <head> 44 <meta http-equiv="Content-Type" content="text/html; charset="iso-8859-1" /> 45 <link rel="openid2.provider openid.server" href="%s/login" /> 46 <link rel="openid2.local_id openid.delegate" href="badger" /> 47 <title>Badger's Home Page</title> 48 </head> 49 <body> 50 <p>Home page for the OpenID authenticated user, <code>badger</code>.</p> 51 </body> 52 </html> 53 """ % deployment_url, ContentType("text/html")), 54 u"???" : 55 StringResource(u""" 56 <html> 57 <head> 58 <meta http-equiv="Content-Type" content="text/html; charset="iso-8859-1" /> 59 <link rel="openid2.provider openid.server" href="%s/login" /> 60 <link rel="openid2.local_id openid.delegate" href="???" /> 61 <title>Home Page for ???</title> 62 </head> 63 <body> 64 <p>Home page for the OpenID authenticated user, <code>???</code>.</p> 65 </body> 66 </html> 67 """ % deployment_url, ContentType("text/html", "iso-8859-1")), 68 "vole" : 69 StringResource(""" 70 <html> 71 <head> 72 <meta http-equiv="Content-Type" content="text/html; charset="iso-8859-1" /> 73 <link rel="openid2.provider openid.server" href="%s/login" /> 74 <link rel="openid2.local_id openid.delegate" href="vole" /> 75 <title>Vole's Home Page</title> 76 </head> 77 <body> 78 <p>Home page for the OpenID authenticated user, <code>vole</code>.</p> 79 </body> 80 </html> 81 """ % deployment_url, ContentType("text/html")), 82 83 # OpenID 2.0 resources. 84 # See: http://docs.oasis-open.org/xri/2.0/specs/cd02/xri-resolution-V2.0-cd-02.html#_Ref129424065 85 # ("3.3 Media Types for XRI Resolution") 86 # See: http://openid.net/specs/openid-authentication-2_0.html#discovery 87 # ("7.3. Discovery") 88 89 "badger2" : 90 StringResource(""" 91 <?xml version="1.0"?> 92 <Service xmlns="xri://$xrd*($v*2.0)"> 93 <Type>http://specs.openid.net/auth/2.0/signon</Type> 94 <URI>%s/login</URI> 95 <LocalID>badger2</LocalID> 96 </Service> 97 """ % deployment_url, ContentType("application/xrd+xml")), 98 u"???2" : 99 StringResource(u""" 100 <?xml version="1.0" encoding="iso-8859-1"?> 101 <Service xmlns="xri://$xrd*($v*2.0)"> 102 <Type>http://specs.openid.net/auth/2.0/signon</Type> 103 <URI>%s/login</URI> 104 <LocalID>???2</LocalID> 105 </Service> 106 """ % deployment_url, ContentType("application/xrd+xml", "iso-8859-1")), 107 "vole2" : 108 StringResource(""" 109 <?xml version="1.0"?> 110 <Service xmlns="xri://$xrd*($v*2.0)"> 111 <Type>http://specs.openid.net/auth/2.0/signon</Type> 112 <URI>%s/login</URI> 113 <LocalID>vole2</LocalID> 114 </Service> 115 """ % deployment_url, ContentType("application/xrd+xml")), 116 }) 117 118 # vim: tabstop=4 expandtab shiftwidth=4