Skip to main content

Easily add GitHub Authentication to your Django Projects

Project description

Django GitHub SSO

Easily integrate GitHub Authentication into your Django projects

PyPI Build PyPI - Python Version PyPI - Django Version License

Welcome to Django GitHub SSO

This library simplifies the process of authenticating users with GitHub in Django projects. It adds a "Login with GitHub" button to your Django admin login page, allowing users to authenticate using their GitHub accounts.

Unlike more complex solutions like django-allauth, Django GitHub SSO focuses on simplicity and ease of use, with minimal configuration required.

Features

  • Simple integration with Django admin
  • Automatic user creation based on GitHub credentials
  • Customizable authentication filters (by domain, organization, or repository)
  • Compatible with various Django admin skins
  • Support for multiple SSO providers
  • Light and dark mode support

Documentation

Full documentation is available at: https://megalus.github.io/django-github-sso/


Requirements

  • Python 3.11+
  • Django 5.0+
  • A GitHub account or organization

Installation

$ pip install django-github-sso

Compatibility

  • Python 3.11, 3.12, 3.13
  • Django 4.2, 5.0, 5.1, 5.2

Older python/django versions are not supported.

Quick Configuration

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

INSTALLED_APPS = [
    # other django apps
    "django.contrib.messages",  # Required 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 OAuth App.

  2. On the GitHub OAuth App settings page, add the address http://localhost:8000/github_sso/callback/ (or your domain) in the "Authorization callback URL" field.

  3. Add your GitHub OAuth credentials to your settings.py:

# settings.py

GITHUB_SSO_CLIENT_ID = "your Client ID here"
GITHUB_SSO_CLIENT_SECRET = "your Client Secret here"
  1. Configure user authorization filters (at least one is required):
# settings.py

# Choose one or more of these options:
GITHUB_SSO_ALLOWABLE_DOMAINS = ["example.com"]  # Check against user's primary email
GITHUB_SSO_ALLOWABLE_ORGS = ["example"]  # User must be a member of all orgs listed
GITHUB_SSO_NEEDED_REPOS = ["example/example-repo"]  # User must have access to all repos listed
  1. Add the Django GitHub SSO URLs to your urls.py:
# urls.py

from django.urls import include, path

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

That's it! Start Django and navigate to http://localhost:8000/admin/login to see the GitHub SSO button:

Environment Variables

For security, it's recommended to use environment variables for your GitHub credentials:

# settings.py
import os

GITHUB_SSO_CLIENT_ID = os.environ.get("GITHUB_SSO_CLIENT_ID")
GITHUB_SSO_CLIENT_SECRET = os.environ.get("GITHUB_SSO_CLIENT_SECRET")

Example project

A minimal Django project using this library is included in this repository under example_github_app/.

  • Read the step-by-step instructions in example_github_app/README.md
  • Use it as a reference to configure your own project settings and URLs

License

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_github_sso-6.0.0.tar.gz (235.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_github_sso-6.0.0-py3-none-any.whl (34.1 kB view details)

Uploaded Python 3

File details

Details for the file django_github_sso-6.0.0.tar.gz.

File metadata

  • Download URL: django_github_sso-6.0.0.tar.gz
  • Upload date:
  • Size: 235.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for django_github_sso-6.0.0.tar.gz
Algorithm Hash digest
SHA256 4b93a9da1fbc4a68fedd701ed89fa7a95cf0ef84e3c8f58e95dce64eb145ff69
MD5 e587c2c04f233e9eb002011de6c575bb
BLAKE2b-256 9a3ed7fb8e800f890442521e0c15df46064c04c4b183b9a45119dcb7aff0b5b9

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_github_sso-6.0.0.tar.gz:

Publisher: publish.yml on megalus/django-github-sso

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_github_sso-6.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_github_sso-6.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 713b4837fb1991607323b325ccbeb7a78d6aefe67c5230e4a8683242abbbe94a
MD5 c30f7dfc7d15e1daca1b181b8d2dd347
BLAKE2b-256 9bf608f31a656c0e7f416a67dbcc0645863090bc6fd8b0b21b5ea6f0bfb7d198

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_github_sso-6.0.0-py3-none-any.whl:

Publisher: publish.yml on megalus/django-github-sso

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page