Overview

ableauth

In order to setup and test this module please follow these steps:

  • hg clone <repo>
  • cd <repo name>
  • virtualenv --no-site-packages .
  • pip install -r requirements.txt
  • cd ableauth
  • python setup.py nosetests

This module was written for Python 2.7. It might work fine with an earlier Python version but some tests will certainly fail.

Caution to the max!

This module makes the potentially dangerous assumption that any inputs are sanitized. It's intentionally meant to be a core api that's only accessed from internal services.


Basic usage

Here is a prototypical example of how you could use ableauth:

import ableauth

user = 'jdoe'
passwd = 'changeme'

# aka login
try:
    auth_token = ableauth.authenticate(user, passwd)
except ableauth.exceptions.AuthenticationError:
    print "Invalid username or passwd!"
    return 1

# aka logout
ableauth.deauthenticate(auth_token)

Here are some other examples of how you'd perform some common operations

import ableauth

username = 'jdoe'
passwd = 'changeme'
groups = ['admins', 'developers']

# Register a user
try:
    activation_code = ableauth.registerUser(username, passwd, groups)
    ableauth.activateUser(activation_code)
except ableauth.exceptions.RegistrationError, msg:
    print str(msg)
    return 1

# Create a new group and add our new user to it
try:
    group = ableauth.createGroup('awesomers')
    group.addUser(username)
except ableauth.exceptions.AbleauthError, msg:
    print str(msg)
    return 1

# add our new user to a group after registration
try:
    groupname = 'staff'
    group = ableauth.group.Group.findOne(name=groupname)
    group.addUser(username)
except ableauth.exceptions.EntityNotFoundError:
    # raised if the group 'staff' doesn't exist
    return 1
except ableauth.exceptions.AbleauthError, msg:
    # raised if something went wrong while adding the user
    print str(msg)
    return 1