Skip to main content

GSSAPI authentication for Django

Provide GSSAPI (SPNEGO) authentication to Django applications.

It’s a rewrite of django-kerberos using python-gssapi.

It’s only tested with MIT Kerberos 5 using package k5test.

Python 2 and 3, Django >1.8 are supported.

Basic usage

Add this to your project urls.py:

url('^auth/gssapi/', include('django_gssapi.urls')),

And use the default authentication backend, by adding that to your settings.py file:

AUTHENTICATION_BACKENDS = (
    'django_gssapi.backends.GSSAPIBackend',
)

View

django-gssapi provide a base LoginView that you can subclass to get the behaviour your need, the main extension points are:

  • challenge() returns the 401 response with the challenge, you should override it to show a template explaining the failure,

  • success(user) it should log the given user and redirect to REDIRECT_FIELD_NAME,

  • get_service_name() it should return a gssapi.Name for your service, by default it returns None, so GSSAPI will match any name available (for example with Kerberos it will match any name in your keytab, like @HTTP/my.domain.com@).

Settings

To make your application use GSSAPI as its main login method:

LOGIN_URL = 'gssapi-login'

Your application need an environment where the GSSAPI mechanism like Kerberos will work, for Kerberos it means having a default keytab of creating one and setting its path in KRB5_KTNAME or you can use GSSAPI_STORE with MIT Kerberos 5 and credential store extension to indicate a keytab:

GSSAPI_STORE = {'keytab': 'FILE:/var/lib/mykeytab'}

You can also force a GSSAPI name for you service with:

import gssapi

GSSAPI_NAME = gssapi.Name('HTTP/my.service.com', gssapi.MechType.hostbased_service)

GSSAPI authentication backend

A dummy backend is provided in django_gssapi.backends.GSSAPIBackend it looks up user with the same username as the GSSAPI name. You should implement it for your use case.

A custom authentication backend must have the following signature:

class CustomGSSAPIBackend(object):
    def authenticate(self, request, gssapi_name):
        pass

The parameter gssapi_name is a gssapi.Name object, it can be casted to string to get the raw name.

Kerberos username/password backend

If your users does not have their browser configured for SPNEGO HTTP authentication you can also provide a classic login/password form which check passwords using Kerberos. For this use django_gssapi.backends.KerberosPasswordBackend, the username is used as the raw principal name.

django-rest-framework authentication backend

To authenticate users with GSSAPI you can use django_gssapi.drf.GSSAPIAuthentication, it uses the configured GSSAPI authentication backend to find an user and returns the GSSAPI name in request.auth.

Metadata

Release files for django-gssapi 1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-gssapi 1.0
File Size Uploaded Provenance
django-gssapi-1.0.tar.gz 11.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for django-gssapi 1.0
File Interpreter ABI Platform
django_gssapi-1.0-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 20.6 kB

Release files / django-gssapi-1.0.tar.gz

Download URL django-gssapi-1.0.tar.gz
Size 11.4 kB
Tags Source
SHA-256 checksum
How to use checksums
e8e88cc5c1f9f7ad755439d32190f06854f77ad30806219c49b6f49f98303cff
BLAKE2b-256 checksum
How to use checksums
9673cd79a29fe1fcf1046f072232f91ccb40a4dca459928c9c96912e8733e914
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.4.2 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.2

Release files / django_gssapi-1.0-py2.py3-none-any.whl

Download URL django_gssapi-1.0-py2.py3-none-any.whl
Size 9.2 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
fc9eb8d02a37321f310d83d0c2d9ed575d4aedc59246d817dc819fd1da82d00c
BLAKE2b-256 checksum
How to use checksums
699747e43dea8fc7b79403dd4a840963235b45f1616cd601e35b4606a8326c11
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.4.2 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.2

Security for django-gssapi 1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page