Easily integrate GitHub Authentication into your Django projects
This library aims to simplify the process of authenticating users with GitHub in Django Admin pages, inspired by libraries like django-admin-sso
$ pip install django-github-sso
- 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
]
-
Navigate to
https://github.com/organizations/<YOUR ORGANIZATION>/settings/applications
, then select or create a newOrg OAuth App
. From that, retrieve yourClient ID
andClient Secret
. -
On the same page, add the address
http://localhost:8000/github_sso/callback/
on the "Authorization callback URL" field. -
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"
- 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
- 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")
),
]
- 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.
This project is licensed under the terms of the MIT license.