Skip to main content

Login to a Django application from a management command

Project description

Django management auth

CI PyPI PyPI - Python Version PyPI - License

Login to a Django application from a management command.

Installation

pip install django-management-auth

Then, add management_auth to INSTALLED_APPS.

Finally, add the required URLs:

# urls.py

urlpatterns += [path(".login-as", include("management_auth.urls"))]

Usage

Authentication happens using a short-lived signed URL, generated from a management command.

./manage.py login_as <username>

This will create a URL for <username>. By default, the URLs are valid for 60 seconds (configurable with --timeout).

Fully-qualified URLs

Where possible, URLs, are displayed fully-qualified, such that they can be quickly clicked to log in.

  • To specify manually, use MANAGEMENT_AUTH_BASE_URL
  • For Wagtail users, WAGTAILADMIN_BASE_URL is used to create the URL.
  • For django.contrib.sites users, SITE_ID is correctly considered

If no base URL is found, a relative path is shown.

Design considerations

  • Tokens are only valid for a short amount of time, intended to prevent reuse / sharing.
  • Tokens are signed URLs, rather than requiring a database table. This means the validation view is faster and more lightweight, and a database leak doesn't risk exposing sessions.
  • Because tokens are signed, they can be used multiple times (however this is a bad idea)

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_management_auth-0.0.0.tar.gz (8.8 kB view hashes)

Uploaded Source

Built Distribution

django_management_auth-0.0.0-py3-none-any.whl (5.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page