Given a User object, how can I list all social associations (for creating a disconnect URL)?

StackOverflow https://stackoverflow.com/questions/19602909

  •  01-07-2022
  •  | 
  •  

Question

I've inherited a project using Django Social Auth. Given a User object, how can I determine which if any social associations are active?

My goal is simply to build a form letting the user disconnect from any backend:

Your login: XXXX
Macebook: [disconnect]
Tweeter: [disconnect]

I know I need to build the right URL ('disconnect/(backend)/(association_id)'), but I can't figure out how to iterate over the proper list of the User's associations.

For a related question see How can i get a specific provider from Django social-auth in a template?

Was it helpful?

Solution

The example application shows how to do it. Here's a snippet:

{# assuming that social_accounts = user.social_auth.all() #}
{% for social in social_accounts %}
    <a href="{% url "socialauth_disconnect_individual" social.provider social.id %}">Disconnect {{ social.provider }}</a>
{% endfor %}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top