efel
efel

Reputation: 1106

python social app (django) - properly save/retrieve user

I'm experimenting with python social auth for my django project and I'm having some trouble understanding the easiest - most straightforward way of creating/saving/retrieving users once logged (eg. via google).

I notice that when logging in through, lets say, gmail - an entry is created in the social auth/Users table. However; the Auth/Users table only has one entry at a time(the person who is logged in).

Now my social auth pipeline goes something like this

SOCIAL_AUTH_PIPELINE = (
    'social.pipeline.social_auth.social_details',
    'social.pipeline.social_auth.social_uid',
    'social.pipeline.social_auth.auth_allowed',
    'social.pipeline.social_auth.social_user',
    'social.pipeline.user.get_username',
    'social.pipeline.mail.mail_validation',
    'social.pipeline.user.create_user',
    'social.pipeline.social_auth.associate_user',
    'social.pipeline.social_auth.load_extra_data',
    'social.pipeline.user.user_details',
    'path.to.my.own',
)

So as you can see I have my own pipeline handler at the very end which I can use to extract more information.

I guess i'm just confused as I do not see many examples online on what is the best way/best practice of storing and retrieving social logged in users from the DB? Should I just extract the social auth user's name,email, etc from the pipeline and create my own model or is this already provided somehow? I guess just to rephrase the question for clarity: Does python social auth for django contain a model for that user social auth table that we can use?

Upvotes: 0

Views: 191

Answers (1)

omab
omab

Reputation: 3701

I think you are confused on how python-social-auth works when you click the login button/link in your site. If there's a user logged in, the the social account will be associated to that user, but if nobody is logged in, a new user instance will be created (unless the social account was already used in your site).

Python-social-auth integrates with django-auth and also supports custom user models, it doesn't provide a user model just the set of tables to track the social account association.

Upvotes: 0

Related Questions