Search code examples
pythondjangopython-social-auth

Python Social Auth - - Django - find url names


So, when using python social auth with django, one has to point the login social button to different urls, depending on the social network. This is an example:

<form action="{% url 'social:begin' 'facebook' %}">
    <button type="submit" class="btn btn-primary"><span class="fa fa-facebook">&nbsp</span>Login with Facebook </button>
</form>

<form action="{% url 'social:begin' 'google-oauth2' %}">
    <button type="submit" class="btn btn-danger"><span class="fa fa-google">&nbsp</span>Login with Google</button>
</form>

As you can see, the url arguments are not intuitive, sometimes they are the name of the social network, like facebook, sometimes it is something more complex like google-oauth2. Is there a way I can figure out what argument to pass into de function? Now, I need login buttons for instagram and twitter. I can't find a clear reference in the docs about this.

Best,

Alejandro.


Solution

  • I think the documentation lacks a reference to this. If anyone needs to find the name of the app to use in the {% url %} declaration, it can be found in the source code under social.apps.backends- each backend is a python file that declares a class, each class declares an attribute called name. In the case of Instagram, it looks like this:

    class InstagramOAuth2(BaseOAuth2):
        name = 'instagram'
        ....
    

    So, that means the social login button should look something like this:

    {% url 'social:begin' 'instagram' %}