sebastian-ardila / google-app-engine-django

Automatically exported from code.google.com/p/google-app-engine-django
Apache License 2.0
0 stars 0 forks source link

Support "basic" Django authentication scheme #177

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
This project ties the apps authentication with the google authentication 
scheme, while this is great, I would like to have the possibilities to decide 
to use the regular django authentication scheme or the google one.

In order to achieve that I propose the following:

1. Stop monkey patching the authentication middleware and in place use the 
middleware plug in mechanism provided the the Django framework. That way 
developer can choose whatever authentication middleware he likes.

2. Provide a mean to configure the user modules (much like AE patch does), so 
user can choose the 'appengine_django.auth.models' or or decide to plug-in 
another model. In my case I added 'appengine_django.auth.django_models' 
containing a suitable replacement of the Django User (and managers) for the  
app engine, but using the the built-in Django authentication.

I basically already done that and I wonder if its worth making/proposing a 
patch for that. These are substantial changes and I need some guidance of the 
usefulness of that for the community.

Original issue reported on code.google.com by sebastie...@gmail.com on 10 Jul 2010 at 2:16

GoogleCodeExporter commented 9 years ago
I think it would be useful.  It would be great if you submitted your patches.

Original comment by dherbst on 10 Jul 2010 at 6:58

GoogleCodeExporter commented 9 years ago
patches are always welcome. Reducing the amount that need to be monkey patched 
at start-up is always a worthy goal. If you can send a series of small, easy to 
review changes to do this in a way that is easy to review we'll be happy to 
consider them.

Original comment by m...@google.com on 12 Jul 2010 at 9:07

GoogleCodeExporter commented 9 years ago
Here's two patches that enable support for django authentication.

The first one, PlugableAuth.diff, changes the Monkeypatcher to load user models 
from the settings variable AUTH_USER_MODULE (if empty it will default on 
'appengine_django.auth.models')

It also change the authentication middleware name from AuthenticationMiddleware 
to GoogleAuthenticationMiddleware (I feel it is less confusing). There is no 
monkey patching required to load the middleware (this was removed) in can be 
done by using the MIDDLEWARE_CLASSES tuple in the settings file. So if you want 
to enable Google authentication, you need to add 
'appengine_django.auth.middleware.DjangoAuthenticationMiddleware' to the 
MIDDLEWARE_CLASSES (on top of what was previously needed).

The second one, DjangoAuth.diff adds a Django User model that is compatible 
with GAE and Django authentication. The necessary models are in 
auth/django_models. It also provide an appropriate authentication backend in 
auth/backends and adds a Django compatible middleware in auth/middlewares.

To enable the django authentication, in the settings file:
1. uncomment/put the following modules in the MIDDLEWARE_CLASSES tuple:
  'django.contrib.sessions.middleware.SessionMiddleware',
  'appengine_django.auth.middleware.DjangoAuthenticationMiddleware',

2. Set the AUTHENTICATION_BACKENDS tuple to 
('appengine_django.auth.backends.ModelBackend',)

3. Set AUTH_USER_MODULE string to:
'appengine_django.auth.django_models'

Finally put the urls mapping to the login/logout views according to the Django 
documentation or by providing your own override.

Original comment by sebastie...@gmail.com on 14 Jul 2010 at 8:18

Attachments:

GoogleCodeExporter commented 9 years ago
Sorry for delay, I'll do my best to review these ASAP.

Original comment by m...@google.com on 26 Oct 2010 at 12:35

GoogleCodeExporter commented 9 years ago
This looks reasonable. I'm not terribly familiar with how applications use the 
Django authentication functionality though. It would be helpful if a couple of 
other interested parties could speak up and confirm that the approach here is 
generally useful to all applications.

Finally, please confirm that you have signed and agreed to the CLA as described 
in the readme. 

Thanks for your contribution.

Original comment by m...@google.com on 18 Nov 2010 at 7:04