samuraisam / django-json-rpc

JSON-RPC Implementation for Django
MIT License
286 stars 83 forks source link

Django 1.4.2 authenticate() compatibility broken (patch included) #35

Closed konsumate closed 12 years ago

konsumate commented 12 years ago

Hi there,

A few commits ago the authentication against Django broke (tested against Django 1.4.2). The jsonrpc/init.py imports the django contrib authenticate() method as _authenticate() which takes a dict only as parameters, but since "*creds" is a positional argument list, this wont work anymore. This seemed to have work before, but broke recently:

diff --git a/jsonrpc/__init__.py b/jsonrpc/__init__.py
index 5886d7f..58d31f9 100644
--- a/jsonrpc/__init__.py
+++ b/jsonrpc/__init__.py
@@ -195,7 +195,7 @@ def jsonrpc_method(name, authenticated=False,
             creds = args[:len(authentication_arguments)]
             if len(creds) == 0:
                 raise IndexError
-            user = _authenticate(*creds)
+            user = _authenticate(username=creds[0], password=creds[1])
             if user is not None:
               args = args[len(authentication_arguments):]
           except IndexError: 

This breaks the feature of having more arguments than username/password given towards authenticate() - but is only a quickfix to restore main Django auth compatibility.

konsumate commented 12 years ago

This should fix the authentication and having the feature for more arguments then only the credentials:

diff --git a/jsonrpc/__init__.py b/jsonrpc/__init__.py
index 5886d7f..ad017b7 100644
--- a/jsonrpc/__init__.py
+++ b/jsonrpc/__init__.py
@@ -195,7 +195,7 @@ def jsonrpc_method(name, authenticated=False,
             creds = args[:len(authentication_arguments)]
             if len(creds) == 0:
                 raise IndexError
-            user = _authenticate(*creds)
+            user = _authenticate(username=creds[0], password=creds[1], *creds[2:])
             if user is not None:
               args = args[len(authentication_arguments):]
           except IndexError: