Commits

Jesper Nøhr  committed 835cd78

switching handlers to oauth only, updating bbapi.py for oauth use, 12 testcases all pass now

  • Participants
  • Parent commits 6a73311

Comments (0)

Files changed (2)

File piston/authentication.py

             if consumer and token:
                 request.user = token.user
                 return True
-                
+        else:
+            print "INVALID REQUEST"
+            print request
+            
         return False
         
     def challenge(self):

File piston/resource.py

         if not meth:
             raise Http404
         
+        # Clean up the request object a bit, since we might
+        # very well have `oauth_`-headers in there, and we
+        # don't want to pass these along to the handler.
+        request = self.cleanup_request(request)
+        
         try:
             result = meth(request, *args, **kwargs)
         except FormValidationError, errors:
         
         return HttpResponse(srl.render(), mimetype=ct)
 
+    @staticmethod
+    def cleanup_request(request):
+        """
+        Removes `oauth_` keys from various dicts on the
+        request object, and returns the sanitized version.
+        """
+        for method_type in [ 'GET', 'PUT', 'POST', 'DELETE' ]:
+            block = getattr(request, method_type, { })
+
+            if True in [ k.startswith("oauth_") for k in block.keys() ]:
+                sanitized = block.copy()
+                
+                for k in sanitized.keys():
+                    if k.startswith("oauth_"):
+                        sanitized.pop(k)
+                        
+                setattr(request, method_type, sanitized)
+
+        return request
+