Saturday, April 27, 2013

django social auth with custom user model is not working

i am trying to implement django social auth in my project and i am having trouble integrating it with my custom user model. Whenever i try to login to facebook, it is throwing an error and always re-directing to LOGIN_ERROR_URL Page.

My settings.py file looks like below.
 
    FACEBOOK_APP_ID              = 'xxxxx'
    FACEBOOK_API_SECRET          = 'xxxxx'
    AUTHENTICATION_BACKENDS = (
       'social_auth.backends.facebook.FacebookBackend',
       'django.contrib.auth.backends.ModelBackend',
    )

    SOCIAL_AUTH_PIPELINE = (
      'social_auth.backends.pipeline.social.social_auth_user',
      'social_auth.backends.pipeline.associate.associate_by_email',
      'social_auth.backends.pipeline.misc.save_status_to_session',
      'social_auth.backends.pipeline.user.create_user',
      'social_auth.backends.pipeline.social.associate_user',
      'social_auth.backends.pipeline.social.load_extra_data',
      'social_auth.backends.pipeline.user.update_user_details',
      'social_auth.backends.pipeline.misc.save_status_to_session',
    )

    LOGIN_URL = '/user/login_register/'
    LOGIN_ERROR_URL = '/user/login_register/'
    LOGIN_REDIRECT_URL = '/'
    LOGOUT_REDIRECT_URL = '/'

    SOCIAL_AUTH_COMPLETE_URL_NAME = 'socialauth_complete'
    SOCIAL_AUTH_ASSOCIATE_URL_NAME = 'socialauth_associate_complete'
    SOCIAL_AUTH_RAISE_EXCEPTIONS = False
    SOCIAL_AUTH_FORCE_POST_DISCONNECT = True
    SOCIAL_AUTH_USERNAME_IS_FULL_EMAIL = True

    SOCIAL_AUTH_USER_MODEL = 'myapp.MyUser'
    FACEBOOK_EXTENDED_PERMISSIONS = ['email']

    AUTH_USER_MODEL = 'myapp.MyUser'


And my custom user model is defined as below (just uses e-mail and doesn't use firstname, lastname or username)

    class MyUserManager(BaseUserManager):
       def create_user(self, email, password=None):
          """
          Creates and saves a User with the given email and password.
          """
          if not email:
             raise ValueError('Users must have an email address')

          user = self.model(
              email=MyUserManager.normalize_email(email),
          )

          user.set_password(password)
          user.save(using=self._db)
          return user


    class MyUser(AbstractBaseUser):

        email = models.EmailField(
            verbose_name='Email address',
            max_length=255,
            unique=True,
            db_index=True,
        )
        is_active = models.BooleanField(default=True)
        is_admin = models.BooleanField(default=False)

        objects = MyUserManager()

        USERNAME_FIELD = 'email'


Now when i try to login to my webapp using facebook login, it takes me to the facebook login credentials page and when i enter the login details, it throws me back to the LOGIN_ERROR_URL page. After i enter the facebook login details, it is not creating a new user in my app.

Can anyone help with what i am missing?


Thanks

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

1 comment: