How to populate user profile with django-allauth provider information?

前端 未结 4 480
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-13 02:36

I\'m using django-allauth for my authentication system. I need that when the user sign in, the profile module get populated with the provider info (in my case facebook).

4条回答
  •  时光取名叫无心
    2020-12-13 03:18

    The pre_social_login signal is sent after a user successfully authenticates via a social provider, but before the login is actually processed. This signal is emitted for social logins, signups and when connecting additional social accounts to an account.

    So it is sent before the signup is fully completed -- therefore this not the proper signal to use.

    Instead, I recommend you use allauth.account.signals.user_signed_up, which is emitted for all users, local and social ones.

    From within that handler you can inspect whatever SocialAccount is attached to the user. For example, if you want to inspect Google+ specific data, do this:

    user.socialaccount_set.filter(provider='google')[0].extra_data
    

    UPDATE: the latest development version makes this a little bit more convenient by passing along a sociallogin parameter that directly contains all related info (social account, token, ...)

提交回复
热议问题