You are correct, Python doesn't support function overloading, because it simply doesn't need it. What happens in your case is that the second declaration of authenticate
overwrites the first one, so you are left with only one version of authenticate
, the one that takes token as a parameter.
What you should do instead is (just an example, there are many possible solutions):
class CustomNCPAuthBackend(object):
"""
This is custom authentication backend.
Authenticate against the webservices call.
The method below would override authenticate() of django.contrib.auth
"""
def authenticate_password(self, username=None, password=None):
print "inside authenticate of username and password with username being : "+username
return None
def authenticate_token(self,token=None):
print "inside authenticate of token with token being : "+token
return None
def authenticate(self, token=None, username=None, password=None):
if token is not None:
return self.authenticate_token(token)
else:
return self.authenticate_password(username, password)
This way it will work with the AuthMiddleWare
you wrote.