Search code examples
pythondjangopython-social-auth

Best way to retrieve email from a open id that does not provide it using python social auth


I've successfully implemented python social auth in my django application however I noticed that twitter does not provide an email address for me to save. is there a way of extending the social auth pipeline so I can ask for a new users email address if one is not provided?


Solution

  • The way to do it is by extending the default pipeline with a function that checks if an email was provided and ask for one in not. Check the example application at https://github.com/omab/python-social-auth/blob/master/examples/django_example, it does that with this pipeline https://github.com/omab/python-social-auth/blob/master/examples/django_example/example/app/pipeline.py.

    Basically the flow is:

    1. User signup with twitter
    2. That pipeline checks if the user is new and if an email was returned by the auth provider
    3. If no email, then redirect the user to a form, otherwise continue (the form POSTs to /complete/twitter, that way the auth process will continue where it stopped)
    4. The pipeline function is ran again, but an email is detected in the request POST data
    5. The pipeline stores the email in the details which is used to create the user later