django-imapauth is a simple IMAP authentification backend for django.
Requirements :
- Django 1.4.3 (tested).
-
Install the app
pypi version
pip install django-imapauthdevelopment version
pip install -e git+http://github.com/ouhouhsami/django-imapauth.git#egg=django-imapauth -
Add
'imapauth.backends.IMAPBackend'to yourAUTHENTICATION_BACKENDSsettingAUTHENTICATION_BACKENDS = ( 'imapauth.backends.IMAPBackend', 'django.contrib.auth.backends.ModelBackend', ) -
Add
IMAPAUTH_HOSTin your settingsIMAPAUTH_HOST = 'my_imap_host'
With django-imapauth, when a user try to authenticate in your system, the IMAPBackend will try to connect to the IMAPAUTH_HOST with his credentials.
Be careful, it's not because a user is authenticated that he can access the admin site. For that, refer to the example below, and use CustomIMAPBackend in AUTHENTICATION_BACKENDS:
from imapauth.backends import IMAPBackend
class CustomIMAPBackend(IMAPBackend):
def authenticate(self, username=None, password=None):
user = super(CustomIMAPBackend, self).authenticate(username, password)
if user is None:
return None
user.is_staff = True
user.save()
return user
IMAPBackend copied from http://www.djangorocks.com/tutorials/creating-a-custom-authentication-backend/creating-the-imap-authentication-backend.html