--- /dev/null
+===================
+django-cas-provider
+===================
+
+---------------------------------
+Chris Williams <chris@nitron.org>
+---------------------------------
+
+OVERVIEW
+=========
+
+django-cas-provider is a provider for the `Central Authentication
+Service <http://jasig.org/cas>`_. It supports CAS version 1.0. It allows
+remote services to authenticate users for the purposes of
+Single Sign-On (SSO). For example, a user logs into a CAS server
+(provided by django-cas-provider) and can then access other services
+(such as email, calendar, etc) without re-entering her password for
+each service. For more details, see the `CAS wiki <http://www.ja-sig.org/wiki/display/CAS/Home>`_
+and `Single Sign-On on Wikipedia <http://en.wikipedia.org/wiki/Single_Sign_On>`_.
+
+INSTALLATION
+=============
+
+To install, run the following command from this directory:
+
+ ``python setup.py install``
+
+Or, put cas_provider somewhere on your Python path.
+
+USAGE
+======
+
+#. Add ``'cas_provider'`` to your ``INSTALLED_APPS`` tuple in *settings.py*.
+#. In *settings.py*, set ``LOGIN_URL`` to ``'/cas/login/'`` and ``LOGOUT_URL`` to ``'/cas/logout/'``
+ before they expire. Default: 5 minutes
+#. In *urls.py*, put the following line:
+ ``(r'^cas/', include('cas_provider.urls')),``
+#. Create login/logout templates (or modify the samples)
--- /dev/null
+{% extends "base.html" %}
+
+{% block title %}
+Login
+{% endblock %}
+
+{% block content %}
+ <form action='.' method='post'>
+ <fieldset>
+ <legend>Log in to your account</legend>
+ {% if errors %}
+ <ul>
+ {% for error in errors %}
+ <li>{{ error|escape }}</li>
+ {% endfor %}
+ </ul>
+ {% endif %}
+ <table style="border: none;">
+ {{ form.as_table }}
+ </table>
+ <p><input type="submit" value="Login"/></p>
+ </fieldset>
+ </form>
+{% endblock %}
--- /dev/null
+{% extends "base.html" %}
+
+{% block title %}
+Logged out
+{% endblock %}
+
+{% block content %}
+ <h3>Logged out</h3>
+
+ <p>You have successfully logged out. To ensure that you are logged out of all services, please close your browser.</p>
+ {% if url %}<p><a href="{{ url }}">Click here</a> to return to {{ url }}</p>{% endif %}
+{% endblock %}
from models import ServiceTicket, LoginTicket
def _generate_string(length=8, chars=string.letters + string.digits):
+ """ Generates a random string of the requested length. Used for creation of tickets. """
return ''.join(Random().sample(string.letters+string.digits, length))
def create_service_ticket(user, service):
+ """ Creates a new service ticket for the specified user and service.
+ Uses _generate_string.
+ """
ticket_string = 'ST-' + _generate_string(29) # Total ticket length = 29 + 3 = 32
ticket = ServiceTicket(service=service, user=user, ticket=ticket_string)
ticket.save()
return ticket
def create_login_ticket():
+ """ Creates a new login ticket for the login form. Uses _generate_string. """
ticket_string = 'LT-' + _generate_string(29)
ticket = LoginTicket(ticket=ticket_string)
ticket.save()
from django.http import HttpResponse, HttpResponseForbidden, HttpResponseRedirect
-from django.shortcuts import get_object_or_404, render_to_response, get_list_or_404
-from django.core.urlresolvers import reverse
-from django.core.exceptions import SuspiciousOperation
+from django.shortcuts import render_to_response
from django.template import RequestContext
from django.contrib.auth.models import User
from django.contrib.auth import authenticate