Adding Persona authentication to your django project

Persona is a decentralized login system made by Mozilla that aims to eliminate site-specific passwords so you can log in with your existing email accounts without having to type in a password.

Persona

Installation

Mozilla provides a library called django-browserid that integrates Persona authentication into Django, so you can simply added to to your requirements.txt or just install via pip :

$ sudo pip install django-browserid

Configuration

Once done you need to follow the following steps :

Add django-browserid to your INSTALLED_APPS,

INSTALLED_APPS = (
# ...
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.staticfiles',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.admin',
'django_browserid',
# ...
)

Add the django_browserid authentication backend :

AUTHENTICATION_BACKENDS = (
# ...
'django.contrib.auth.backends.ModelBackend', # required for admin
'django_browserid.auth.BrowserIDBackend',
# ...
)

Add the django_browserid context processor :

TEMPLATE_CONTEXT_PROCESSORS = (
# ...
'django_browserid.context_processors.browserid',
# ...
)

and finally you need to set your site url :

SITE_URL = 'https://example.com'

I have created a working demo project on github to play with, you can still check the docs or comment here if it doesn't work for you.

Mentioned on