Commits

Donald Stufft committed 922c5ad

Port the /id/* urls for OpenID over to Werkzeug

  • Participants
  • Parent commits 1e87a05
  • Branches werkzeug

Comments (0)

Files changed (1)

             routing.Rule("/daytime/", endpoint="daytime", methods=["GET"]),
             routing.Rule("/mirrors/", endpoint="mirrors", methods=["GET"]),
             routing.Rule("/security/", endpoint="security", methods=["GET"]),
+
+            # OpenID
+            routing.Rule("/id/", endpoint="openid_discovery"),
+            routing.Rule("/id/<username>/", endpoint="openid_user"),
         ])
 
     @property
             # Dispatch to the endpoint
             return getattr(self, "do_%s" % endpoint)(request, database, **args)
 
-            if script_name == '/id':
-                return self.run_id(request, database)
-
             request = self.authenticate(request, database)
 
             # Now we have a username try running OAuth if necessary
 
         return Response(headers=headers)
 
-    def run_id(self):
-        path = self.env.get('PATH_INFO')
-        if not path:
-            self.openid_discovery()
-        else:
-            self.openid_user(path)
-
     def home(self, nav_current='home'):
         self.write_template('home.pt', title='PyPI - the Python Package Index',
                             headers={'X-XRDS-Location':self.url_machine+'/id'})
     #
     # OpenID Provider
     #
-    def openid_discovery(self):
-        """Return an XRDS document containing an OpenID provider endpoint URL."""
+    def do_openid_discovery(self, request, database):
+        """
+        Return an XRDS document containing an OpenID provider endpoint URL.
+        """
         payload = '''<xrds:XRDS
                 xmlns:xrds="xri://$xrds"
                 xmlns="xri://$xrd*($v*2.0)">
                 </XRD>
             </xrds:XRDS>
         ''' % (self.config.url+'?:action=openid_endpoint')
-        self.handler.send_response(200)
-        self.handler.send_header("Content-type", 'application/xrds+xml')
-        self.handler.send_header("Content-length", str(len(payload)))
-        self.handler.end_headers()
-        self.handler.wfile.write(payload)
-
-    def openid_user(self, user):
-        """Return an XRDS document containing an OpenID provider endpoint URL."""
+        return Response(payload, content_type="application/xrds+xml")
+
+    def do_openid_user(self, request, database, user):
+        """
+        Return an XRDS document containing an OpenID provider endpoint URL.
+        """
         payload = '''<xrds:XRDS
                 xmlns:xrds="xri://$xrds"
                 xmlns="xri://$xrd*($v*2.0)">
                 </XRD>
             </xrds:XRDS>
         ''' % (self.config.url+'?:action=openid_endpoint')
-        self.handler.send_response(200)
-        self.handler.send_header("Content-type", 'application/xrds+xml')
-        self.handler.send_header("Content-length", str(len(payload)))
-        self.handler.end_headers()
-        self.handler.wfile.write(payload)
+        return Response(payload, content_type="application/xrds+xml")
 
     def openid_endpoint(self):
         """Handle OpenID requests"""