MongoEngine provides two distinct methods to provide authentication in django:
Only the first one will work with python-social-auth (as of v0.1.17).
Classic Authentication
Basically, you just need to use a custom authentication backend:
AUTHENTICATION_BACKENDS = (
'mongoengine.django.auth.MongoEngineBackend',
)
You shouldn't set AUTH_USER_MODEL
, as this is used to define a Custom User Model. Here, Django's models are just ignored.
The user document class used to store users is defined by MONGOENGINE_USER_DOCUMENT
, which defaults to 'mongoengine.django.auth.User'
. You can update this value if you want to write your custom user class.
Then, it's just a matter of setting the same user document class for Social-Auth, as omab pointed:
SOCIAL_AUTH_USER_MODEL = 'mongoengine.django.auth.User'
This is the option python-social-auth supports.
Custom User Model
Django 1.5 introduced a new way to define a custom user model class, which this method makes use of. Authentication will be done using the standard Django authentication backend:
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
)
AUTH_USER_MODEL
must be set to 'mongo_auth.MongoUser'
, which does point to mongoengine.django.mongo_auth.MongoUser
(using Django's app_name.model_name
notation).
This MongoUser
model is not directly used (as it's a Django Model), it's just a way to tell Django to use another model using Django's Custom User Model. The manager on this model will simply return MongoEngine documents defined by MONGOENGINE_USER_DOCUMENT
as above.
Unfortunately, this method is not supported by python-social-auth, as it expects AUTH_USER_MODEL
to be a MongoEngine document, while it is actually a proxy Django Model.
I created a Pull Request to try and fix the issue.