Note that there are some explanatory texts on larger screens.

plurals
  1. POdjango custom authentication backend with custom middleware (both username,password and token absed auth)
    text
    copied!<p>I am in a situation where I need to make a custom authentication and custom middleware to authenticate and authorize the user. I have to chek the username password params in the POST request or if the cookie is set or not for token based authentication. Now, as I know that function overloading is not allowed in python, how could I achieve it. I am putting the code below for custom auth and custom middleware.</p> <p>Custom Middleware:</p> <pre><code>from django.contrib.auth import authenticate class AuthMiddleWare(object): def process_request(self, request): if request.path != '/favicon.ico': print "inside process_request " + request.path if request.method == 'POST' and request.POST.has_key('username' ) and request.POST.has_key('password'): authenticate(username = request.POST.get('username'),password = request.POST.get('password')) if 'SPRING_SECURITY_REMEMBER_ME_COOKIE' in request.COOKIES: authenticate(token = request.COOKIES.get('SPRING_SECURITY_REMEMBER_ME_COOKIE')) return None </code></pre> <p>And the custom auth backend :</p> <pre><code>from core.api import NcpAPI 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(self, username = None, password = None): print "inside authenticate of username and password with username being : "+username return None def authenticate(self,token=None): print "inside authenticate of token with token being : "+token return None </code></pre> <p>The problem is even when I am checking for username and password in post request it calls the token one as token is there, but how could I force it somehow? </p> <p>I tried deleting the cookie and trying again but still it doesn't fire up the authentication function with username and password as params. </p> <p>What could be solution for this please?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload