Add GitHat authentication to Django applications. REST API integration, custom auth backends, and multi-tenant organization support.
Django apps can use GitHat for user authentication via the REST API. Create a custom backend that authenticates users against api.githat.io and creates local Django user records.
Build an AUTHENTICATION_BACKEND that validates GitHat JWT tokens. On successful validation, get or create a Django User record. This bridges GitHat's identity system with Django's permissions.
Create middleware that intercepts requests, validates Bearer tokens against GitHat, and sets the user context. Exclude public paths like login and static files from validation.
pip install requests django
# backends.py
import requests
from django.contrib.auth.models import User
class GitHatBackend:
GITHAT_API = 'https://api.githat.io'
def authenticate(self, request, token=None):
resp = requests.get(f'{self.GITHAT_API}/auth/me',
headers={'Authorization': f'Bearer {token}'})
if resp.status_code != 200:
return None
data = resp.json()['user']
user, _ = User.objects.get_or_create(
email=data['email'],
defaults={'username': data['email'], 'first_name': data['name']}
)
return user
Try GitHat free
Ship authenticated apps in minutes, not weeks.