Search code examples
pythondjangooauthpython-social-authdjango-socialauth

Python Social Auth Django Github OAuth


I'm trying to integrate my Django website with Github Authentication using Python-Social-Auth library

Configuration so far:

settings.py

INSTALLED_APPS += (
 ...
 "social_django",
 "social_core",

)

AUTHENTICATION_BACKENDS = [
    "account.auth_backends.UsernameAuthenticationBackend",
    "social_core.backends.github.GithubOAuth2",
]

TEMPLATES = [
    {
            ...
            'context_processors': [
                ...
                "social_django.context_processors.backends",
                "social_django.context_processors.login_redirect",
            ],
        },
    },
]

login.html

<a href="{% url "social:begin" "GithubOAuth2" %}">Github</a>

urls.py

url("^socialaccounts/", include('social_django.urls', namespace='socialaccounts')),

But when I click the link, it shows a 404 Not Found Page. And where do I put the secret key and other github configuration?


Solution

  • They go in the project's settings.py file.

    INSTALLED_APPS += (
     ...
     "social_django",
     "social_core",
    
    )
    
    AUTHENTICATION_BACKENDS = [
        "account.auth_backends.UsernameAuthenticationBackend",
        "social_core.backends.github.GithubOAuth2",
    ]
    
    TEMPLATES = [
        {
                ...
                'context_processors': [
                    ...
                    "social_django.context_processors.backends",
                    "social_django.context_processors.login_redirect",
                ],
            },
        },
    ]
    
    SOCIAL_AUTH_GITHUB_KEY = ''
    SOCIAL_AUTH_GITHUB_SECRET = ''