This is a brief tutorial on how to setup a new django-project with openid authentication support.
django-authopenid basics
We will use django-authopenid for this project. It provides support for openid-2.x which is not available in other projects like django-openid.
In a login process, after a successful authentication via OpenID, django-authopenid requires the user to connect the OpenID-URL with a local user (existing or newly created). Creating a new user is as simple as providing an username and email; no activation is required by default. This is the (simplified) authentication process of django-authopenid:

Django-authopenid associates the users and OpenID-URL's in a database-table called "user_associations", which is available via the admin interface. The package provides quite some functionality like password reset, password change, ... and provides this URL structure by default:
/account/ .................... main page of account for user /account/signin/ ............. go to signin page /account/signout/ ............ signout url /account/signin/complete/ .... register openid after signin /account/signup/ ............. legacy authentification /account/email/ .............. change email page /account/delete/ ............. delete account /account/openid/ ............. associate a new openid for an account /account/password/ ........... change password page /account/password/confirm/ ... confirm change of password /account/sendpw/password/ .... send a new password
More infos can be found in the project's README.
Requirements
First of all we need to setup the environment with a few required packages:
- Python 2.4 or higher
- Django 0.96.3 or higher
- python-openid-2.x
cd /tmp wget http://openidenabled.com/files/python-openid/packages/python-openid-2.2.... tar -xvf python-openid-2.2.1.tar.gz cd python-openid-2.2.1 python setup.py install
- python-elementtree (required by django-authopenid)
wget http://effbot.org/media/downloads/elementtree-1.2.6-20050316.tar.gz ... python setup.py install
- python-httplib2 (available with the package manager of your choice)
Project Setup
Have a look at the websvn for the structure of the demo-project. There are downloads for the full project we are going to create in the next steps zipped and as tar.gz. If you download and extract one, you can skip directly to starting the server.
Let's start with creating our project, which will have this basic directory-structure:
/demoproject/ ....................... urls.py, settings.py, manage.py /demoproject/main/ .................. our own app (models.py, views.py) /demoproject/django_authopenid/ ..... the django-authopenid libraries /demoproject/templates/ ............. all templates for our project and django-authopenid
Let's create the project with this structure now:
django-admin startproject demoproject cd demoproject python manage.py startapp main svn checkout http://django-authopenid.googlecode.com/svn/trunk/django_authopenid mv django_authopenid/templates .
Thats pretty much it :-) Perhaps get rid of the .svn directories:
rm -rf django_authopenid/.svn templates/.svn templates/authopenid/.svn
At this point we want to set up our settings.py:
- Database support (eg. sqlite3 with database_name "main.db")
- OpenIDMiddleware to MIDDLEWARE_CLASSES
MIDDLEWARE_CLASSES = ( ... 'django_authopenid.middleware.OpenIDMiddleware', ) - Add LOGIN_URL somewhere:
LOGIN_URL = "/account/signin/"
- Add django_authopenid and our main app to INSTALLED_APPS:
INSTALLED_APPS = ( ... 'django_authopenid', 'demoproject.main', ) - Add the template directory:
import os.path TEMPLATE_DIRS = ( os.path.join(os.path.dirname(__file__), 'templates'), ) - Maybe set variables for email
echo "{% block content %}{% endblock %}" > templates/base.htmlFinally, we want to add the django-authopenid url's to urls.py:
(r'^account/', include('django_authopenid.urls')),And last but not least: creating the database.
python manage.py syncdb
Starting the Server
The basic setup is completed, let's start the django-server!
python manage.py runserver
Test the login-procedure and account-functions by browsing to http://localhost:8000/account/
Once a user logged in via OpenID, the users URL is stored in request.openid
This could be an example html template:
{% extends "base.html" %}
{% block content %}
<h1>Django AuthOpenID Test</h1>
<p>You are logged in as {{ request.user }}</p>
<p>Your OpenID URL: {{ request.openid }}</p>
<p><a href="/account">Account</p>
{% endblock %}
Hope this could help a bit and you enjoy using OpenID in your Django projects!

ragadozoja, cialis efectos secundarios, 8PP, acheter cialis en france, epmu, comprar cialis, exg,
educativos, acheter cialis en france, :-), cialis acheter, :]]],
lastuto, viagra ou cialis, 84020, cialis generico comprar, cevuqw, effetti collaterali cialis, 1959,
veszik, comprar cialis generico, lgq, achat cialis france, >:-PPP,
dagar, cialis generico comprar, =-PP, viagra cialis generica, syrubc,
classificato, comprare viagra italia cialis online, =), comprar cialis generico en espa?a, 12763, viagra cialis generica, 84161,
flytte, cialis belgique, 2564, generica cialis, obxp,
begav, acheter cialis original, ule, cialis 20 mg, 272,
efteraret, cialis viagra, mjboir, acheter cialis original, plnq,
realmente, cialis belgique, :-), acheter viagra cialis, =-D, cialis effet secondaire, 74377,
organisation, cialis generico comprar, incqlx, cialis generico, =]]], cialis generico, =-[,
szabadon, generica cialis, 194597, achat cialis france, =-]],
rend, achat viagra france cialis levitra, nbnr, acheter cialis, hff,
assume, viagra ou cialis, >:((, achat cialis france, %-)),
murica, cialis sin receta, 8), generica cialis, 24865,
transformee, comprar cialis generico, 125622, cialis acheter, :-DDD,
accompagnato, cialis acheter, 8391, viagra cialis generica, 161053, vendita cialis, 013,
deriteni, cialis efectos secundarios, dfbyz, acheter cialis, :OO, cialis 5 mg, %-OOO,
godkender, acheter cialis en france, :-))), cialis viagra, 311053, cialis effet secondaire, 91894,
elemezgetni, cialis generico comprar, 258358, comprare viagra italia cialis levitra, 498, comprare viagra italia cialis online, 3841,
kepeknel, acheter cialis en france, 8-], viagra cialis generica, abk,
sogemulighed, cialis efectos secundarios, 33962, cialis form indian pharmacies, zwepbk,
timmervagg, prix cialis, hzcv, effetti collaterali cialis, %[, achat cialis france, 031531,
oppbygging, comprar cialis, 914, cialis effet secondaire, 74474,
planering, acheter cialis en france, 3503, comprar cialis generico en espa?a, =[, acheter cialis original, 8]],
omtaler, cialis belgique, %PPP, cialis controindicazioni, :-DDD, achat cialis france, 8))),
valille, effetti cialis, >:DD, comprar cialis generico, 8-PPP,
kleinserien, effetti collaterali cialis, 6927, cialis effet secondaire, lll,
leale, achat viagra france cialis levitra, 8623, comprar cialis generico en espa?a, >:-)),
pinnoitteena, comprare viagra italia cialis online, ztacja, cialis 20 mg, %-[[,
Post new comment