Search code examples
django-socialauth

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


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?


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 %}