AuthKit, valid_password and wraptools


I’m new to AuthKit, and I wanted to override the method authkit.authenticate.valid_password for the form way of handling authentication. But could not figure out a good way of doing this. It appears that they only way overriding this method is to use the forward handler, but then again I had AuthKit working more or less the way I wanted using the form handler.

So how do you go about overriding one method in a library that you’re using? Well in Python you can use the wraptools module. This allows you to override a method using decorators. For example,

@replaces(authkit.authenticate.valid_password)
def valid_password(environ, username, password):
    try:
        # validate the username/password
        return True
    except YourLoginException:
        return False

One Response to “AuthKit, valid_password and wraptools”

  1. AllanC Says:

    I have been tackling the same problem.

    I was unable to get your solution working due to my own inexperience with Python.

    It is possible to put in the pylons development.ini file a reference to a custom valid_password method with the option

    authkit.form.authenticate.function=trackmgr.controllers.Login:valid_password

    where Login is a file called Login.py and :valid_password is the method name.

    This example was found on http://groups.google.com/group/authkit/browse_thread/thread/5405fba6649fecab

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.