Skip to main content

Basic auth utilities for Django.

Requires

Tested under…

  • Python

    • 3.6

    • 3.7

    • 3.8

    • 3.9

  • Django

    • 2.2

    • 3.0

    • 3.1

Installation

pip install django-basicauth

Usage

from basicauth.decorators import basic_auth_required

@basic_auth_required
def myview(request):
    ...

or by a middleware.

MIDDLEWARE = (
    'basicauth.middleware.BasicAuthMiddleware',
    ...
)

Basic Auth for specific requests only

To apply basic auth for specific requests, Use target_test argument.

In the below code, anonymous users will be required Basic Auth Authenticated users can pass it without Basic … header.

from basicauth.decorators import basic_auth_required

@basic_auth_required(
    target_test=lambda request: not request.user.is_authenticated
)
def myview(request):
    ...

target_test accepts typing.Callable[[HttpRequest], bool], and if the callable returns True, Basic Auth will be required.

Applying decorator to CBVs

To apply @basic_auth_required decorator to Class Based Views, use django.utils.decorators.method_decorator.

from django.utils.decorators import method_decorator
from basicauth.decorators import basic_auth_required

@method_decorator(basic_auth_required, name='dispatch')
class YourView(TemplateView):
    template_name = "my-template.html"

Settings

  • BASICAUTH_USERS (required): Dictionary including keys as username and values as passwords.

  • BASICAUTH_REALM: realm string, default is “Secure resource”.

  • BASICAUTH_DISABLE: Disable all of barriers by this library.

Changes

0.5.3 (2020-11-17)

  • Added supporting Django3 and Python3.8,3.9
    • Thanks @rhoboro !

  • Dropped Py2, Django1.11

0.5.2 (2019-04-06)

  • Added supporting Django2.2

0.5.1 (2018-08-06)

  • Added supporting Django2.1
    • Thanks @rhymes

0.5 (2018-05-09)

  • Added supporting Django2.0
    • Thanks @timheap

0.4.2 (2017-11-27)

  • Fixed to avoid timing attacks
    • Lots of thanks for Hugo Castilho

0.4.1 (2017-10-20)

  • Added target_test argument for the decorator.

0.4 (2017-09-30)

  • Supported Python 2.7

  • Dropped Django1.9

  • Supported Django 1.10+ style middleware

0.3 (2017-08-28)

  • Added BASICAUTH_DISABLE setting

  • Changed API of basicauthutils.validate_request
    • Fixed to return True/False

    • Adding REMOTE_USER by this function

0.2.1 (2017-08-28)

  • Officially supported Django 1.11, 1.10, 1.9

0.2 (2016-03-31)

0.1 (2015-04-20)

  • Initial

Release files for django-basicauth 0.5.3

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-basicauth 0.5.3
File Size Uploaded
django-basicauth-0.5.3.tar.gz 5.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-basicauth 0.5.3
File Interpreter ABI Platform
django_basicauth-0.5.3-py3-none-any.whl Python 3 none any Details

Total release size: 11.7 kB

Release files / django-basicauth-0.5.3.tar.gz

Download URL django-basicauth-0.5.3.tar.gz
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
15e9e366f698f53c71b1e794dafea060f990a2ac556bae6b7330dd25324a091c
BLAKE2b-256 checksum
How to use checksums
f752b955427ff9d1a8e0639ac34089d7f94e427a46ae03a4ea0de013dac97207
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.52.0 CPython/3.8.5

Release files / django_basicauth-0.5.3-py3-none-any.whl

Download URL django_basicauth-0.5.3-py3-none-any.whl
Size 6.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e5e47d1acdc1943bedcc1bf673059d6c15e257dfe9eef67a22fb824f79546c0d
BLAKE2b-256 checksum
How to use checksums
9e315d86b04b2eab838ed2ab21a711b3b1ac866177f349b13e10412e276ff891
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.52.0 CPython/3.8.5

Release history Release notifications | RSS feed

This release

0.5.3 This release

2 release files

0.5.2

3 release files

0.5.1

2 release files

0.5

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4

2 release files

0.3

2 release files

0.2.1

2 release files

0.2

1 release file

0.1

1 release file

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