It's actually not that hard, even if you want to require auth only for
specific areas. A middleware like this might do the trick (with a
little tweaking):
from django.contrib.auth.decorators import login_required
class AuthRequiredMiddleware(object):
def process_view(self, request, view_func, view_args, view_kwargs):
if ... (fill in test here to see if it's a URL or view you
want to require auth for):
return login_required(view_func)(request, *view_args, **view_kwargs)
--
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."
Well, they can share a database and auth against a single users table
(we do this all the time), or you can have an external authentication
source and write an auth backend which knows how to talk to it and
authenticate against it, then use it on all the sites which need it.
I've seen people doing LDAP and various other corporate-love-fest auth
systems that way.
If they're all on the same domain or subdomains of the same domain,
and you do the cookies right, it is.
If they're not all on the same domain (or authentication realm for
Apache-based auth), there's nothing Django can really do to help you,
as far as I know.
We have 'true' SSO working with multiple Django applications at my
workplace, using CAS and an authentication backend based on
django-cas; IIRC we're planning to release an updated version to the
world at large. I'll check on this tomorrow.
> Just sharing the same user database doesn't necessarily help in that
> you still have to log in to each application.
We actually don't share database across the applications, so logging
into each instance (which might just consist of a bunch of redirects
if the user's already authenticated to the CAS server) creates a new
user object in the Django instance's local database. This even works
for multiple instances on the same domain (or not), as long as you
remember to use a different SESSION_COOKIE_NAME for each instance.
Conceptually, the SSO is done one layer deeper than Django. Individual
Django instances are themselves clients to the SSO service (CAS, in
this case).
Of course, I don't think this has anything to do with what the OP was
needing, but your post reminded me of this anyway.
Adam