Skip to content

megalus/django-github-sso

Repository files navigation

Django GitHub SSO

Easily integrate GitHub Authentication into your Django projects

PyPI Build PyPI - Python Version PyPI - Django Version

Welcome to Django GitHub SSO

This library aims to simplify the process of authenticating users with GitHub in Django Admin pages, inspired by libraries like django-admin-sso


Documentation


Install

$ pip install django-github-sso

Configure

  1. Add the following to your settings.py INSTALLED_APPS:
# settings.py

INSTALLED_APPS = [
    # other django apps
    "django.contrib.messages",  # Need for Auth messages
    "django_github_sso",  # Add django_github_sso
]
  1. Navigate to https://github.com/organizations/<YOUR ORGANIZATION>/settings/applications, then select or create a new Org OAuth App. From that, retrieve your Client ID and Client Secret.

  2. On the same page, add the address http://localhost:8000/github_sso/callback/ on the "Authorization callback URL" field.

  3. Add both credentials in your settings.py:

# settings.py

GITHUB_SSO_CLIENT_ID = "your Client ID here"
GITHUB_SSO_CLIENT_SECRET = "your Client Secret  here"
  1. Let Django GitHub SSO auto create users which have access to your repositories:
# settings.py

GITHUB_SSO_NEEDED_REPOS = ["example/example-repo"]  # user needs to be a member of all repos listed
  1. In urls.py please add the Django-Github-SSO views:
# urls.py

from django.urls import include, path

urlpatterns = [
    # other urlpatterns...
    path(
        "github_sso/", include("django_github_sso.urls", namespace="django_github_sso")
    ),
]
  1. And run migrations:
$ python manage.py migrate

That's it. Start django on port 8000 and open your browser in http://localhost:8000/admin/login and you should see the GitHub SSO button.


License

This project is licensed under the terms of the MIT license.