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 4.2+
  • 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-5.0.2.tar.gz (24.6 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-5.0.2-py3-none-any.whl (33.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_github_sso-5.0.2.tar.gz
  • Upload date:
  • Size: 24.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.0 CPython/3.12.1 Linux/6.11.0-1018-azure

File hashes

Hashes for django_github_sso-5.0.2.tar.gz
Algorithm Hash digest
SHA256 e24a4d14fbd2d3b323889c3bba0b53e595c6716125a6b454ccd826946f378e67
MD5 c29bcd6e7b0d8254b0fdfaccac844af6
BLAKE2b-256 57e49900ea0520a98fbaa6ec98886bd38ff193127a0b940b7b57d27f1a032698

See more details on using hashes here.

File details

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

File metadata

  • Download URL: django_github_sso-5.0.2-py3-none-any.whl
  • Upload date:
  • Size: 33.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.0 CPython/3.12.1 Linux/6.11.0-1018-azure

File hashes

Hashes for django_github_sso-5.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a878dd4ccd2a2f602d9d359214fe8f334f181333bb9169b43639fc3b0c0082bf
MD5 c8f08897df19a99e2fd3b19b3a26ee3b
BLAKE2b-256 80d9f028d41f36d47d4a8ae2c456213b08811f5044b1a1f2fd2e4f08c44580b5

See more details on using hashes here.

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