Question

I want to create 2 different signup mechanisms for 2 different user types, i.e., consumer users and vendor users. What is the simplest way to do this with python-social-auth?

To focus the discussion, let's say that there are 2 signup pages: example.com/consumer-signup and example.com/vendor-signup. This question boils down to how I can pass a value from each page to the social auth pipeline or to an authenticator like facebook so that I can retrieve that same value after authentication is complete.

Thanks

Was it helpful?

Solution

You'll likely want to use SOCIAL_AUTH_FIELDS_STORED_IN_SESSION to configure query parameters you can pass into your socialauth_begin endpoint. You can then retrieve this value in your SOCIAL_AUTH_PIPELINE and access the request.session for this value.

Something like:

Your Settings

SOCIAL_AUTH_FIELDS_STORED_IN_SESSION = ('user_type', )

Your Login Template

a href="{% url socialauth_begin '[backend]' %}?user_type=vendor">Sign-in as Vendor</a>

Your Pipeline Stage

def set_user_type(strategy, details, response, user=None, is_new=False, *args, **kwargs):
    user_type = strategy.session.get('user_type')
    if user_type == 'vendor':
        ...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top