1

I am trying to learn how to integrate python social auth into a django project.

It seems to work, because I can log into my test application, but it seams that the user is never stored to the db and I can't understand why, since I don't get any error.

Here's my conf

INSTALLED_APPS = (
    ...
    'social.apps.django_app.default',
    'messaging'
)

AUTHENTICATION_BACKENDS = (
    'social.backends.facebook.FacebookOAuth2',
    'social.backends.email.EmailAuth',
    'django.contrib.auth.backends.ModelBackend',
)

SOCIAL_AUTH_FACEBOOK_KEY='XX'
SOCIAL_AUTH_FACEBOOK_SECRET='YYY'
FACEBOOK_EXTENDED_PERMISSIONS = ['email']
SOCIAL_AUTH_FACEBOOK_SCOPE = ['email']

LOGIN_URL = '/login/'
LOGIN_REDIRECT_URL = '/home/'
LOGOUT_REDIRECT_URL = '/'
URL_PATH = ''
SOCIAL_AUTH_STRATEGY = 'social.strategies.django_strategy.DjangoStrategy'
SOCIAL_AUTH_STORAGE = 'social.apps.django_app.default.models.DjangoStorage'

TEMPLATE_CONTEXT_PROCESSORS = (
    'django.contrib.auth.context_processors.auth',
    'social.apps.django_app.context_processors.backends',
    'social.apps.django_app.context_processors.login_redirect',
)

My idea is just to use django default model for the user, so I haven't defined any extension for it.

Do you have any idea why users are not created at login?

UPDATE

I noticed something that looks weird, at least to me. The first admin user which is created when doing syncdb has the same first and last name of the facebook account I am using to test the application. I thought that it was not going to be used and that another user had to be created, but while checking the database i saw that auth_user.last_login was updated accordingly to the login performed with facebook.

So I have these two questions:

  1. is it correct that python social auth checks if a user with the same first and last name is already present in auth_user then it uses that particular user instead of creating another one?
  2. how can I avoid the situation where user Foo Bar on facebook and user Foo Bar on Twitter are not the same person?
4

1 回答 1

0

快速回答您的问题:

  1. 不需要任何东西来实现这一点。

在我看来,您在单击Login with Facebook链接之前已使用该管理员用户登录。python-social-auth将获取当前登录的用户并将社交帐户与其关联(如果有任何用户登录),否则它将创建一个新帐户。但是,如果社交帐户已在您的站点中使用,它将登录相关用户,或丢弃指示社交帐户已在使用中的异常。

您可以使用以下方法检查相关用户到社交帐户:

from social.apps.django_app.default.models import UserSocialAuth

for social in UserSocialAuth.objects.all():
  print social.provider, social.user.id, social.user.username

这就是我在你的情况下会做的:

  1. 删除数据库,或删除表中的内容social_auth_usersocialauth
  2. 转到/admin并确保您已注销
  3. 尝试再次使用 Facebook 登录

这次应该创建一个新的用户帐户。

于 2014-05-03T17:11:10.093 回答