django-cats/cats/views.py
Jan Dittberner 3f4e005cf3 Implement client certificate authentication
- add a cats.authentication.ClientCertificateBackend authentication
  backend implementation that extracts the used fields from a client
  certificate
- configure the AUTHENTICATION_BACKENDS setting to use the
  ClientCertificateBackend
- add cryptography dependency to parse certificate data
- add gunicorn as production dependency
- add a development configuration for Gunicorn
- document how to pass client certificate information via nginx reverse
  proxy
- add a certificate_login view and a basic home_page view and add
  corresponding URL patterns
- ignore PEM encoded files and temporary gunicorn files
2024-09-20 12:42:44 +02:00

23 lines
691 B
Python

from django.contrib.auth import authenticate
from django.http import HttpResponseForbidden, HttpResponseRedirect, HttpResponse
from django.shortcuts import redirect
from django.utils.translation import gettext as _
# Create your views here.
def certificate_login(request):
certificate = request.META.get('HTTP_X_SSL_CERT', None)
user = authenticate(request, encoded_certificate=certificate)
if not user:
return HttpResponseForbidden(_("you have not sent a valid client certificate"))
if "next" in request.GET:
return HttpResponseRedirect(request.GET["next"])
return redirect("home")
def home_page(request):
return HttpResponse("Hello World!")