Skip to main content

django-sesame

Introduction

django-sesame provides one-click login for your Django project. It uses specially crafted URLs containing an authentication token, for example: https://example.com/?url_auth_token=AAAAARchl18CIQUlImmbV9q7PZk%3A89AEU34b0JLSrkT8Ty2RPISio5

It’s useful if you want to share private content without requiring your visitors to remember a username and a password or to go through an authentication process involving a third-party.

django-sesame is tested with:

  • Django 1.11 (LTS) and 2.0.

  • all supported Python versions.

It requires django.contrib.auth. It’s compatible with custom user models. It uses django.contrib.session when it’s available.

Technically, django-sesame can provide stateless authenticated navigation without django.contrib.sessions, provided all internal links include the authentication token, but that increases the security issues explained below.

django-sesame is released under the BSD license, like Django itself.

A few words about security

Before using django-sesame in your project, you should review the following advice carefully.

The major security weakness in django-sesame is a direct consequence of the feature it implements: whoever obtains an authentication token will be able to log in to your website. URLs end up in countless insecure places: emails, referer headers, proxy logs, browser history, etc. You can’t avoid that. So use django-sesame only for mundane things.

If a data leak would affect you in non-trivial ways, don’t use this library. You have been warned.

Otherwise, a reasonable attempt has been made to provide a secure solution. django-sesame uses Django’s signing framework to create signed tokens.

Tokens are tied to the primary key and the password of the corresponding user. Changing the password invalidates the token. When the authentication backend uses salted passwords — that’s been the default in Django for a long time — the token is invalidated even if the new password is identical to the old one.

By default, tokens never expire. If you want them to expire after a given amount of time, set the SESAME_MAX_AGE setting to a duration in seconds. Then each token will contain the time it was generated at and django-sesame will check if it’s still valid at each login attempt.

How to

  1. Add sesame.backends.ModelBackend to AUTHENTICATION_BACKENDS:

    AUTHENTICATION_BACKENDS += ['sesame.backends.ModelBackend']
  2. Add sesame.middleware.AuthenticationMiddleware to MIDDLEWARE:

    MIDDLEWARE += ['sesame.middleware.AuthenticationMiddleware']
  3. Generate authentication tokens with sesame.get_query_string(user).

That’s all!

Generating URLs

django-sesame provides two functions to generate authenticated URLs.

  1. sesame.utils.get_query_string(user) returns a complete query string that you can append to any URL to enable one-click login.

  2. sesame.utils.get_parameters(user) returns a dictionary of GET parameters to add to the query string, if you’re already building one.

Share resulting URLs with your users while ensuring adequate confidentiality.

By default, the URL parameter is called url_auth_token. You can set the SESAME_TOKEN_NAME setting to a shorter name that doesn’t conflict with query string parameters used by your application.

Metadata

Release files for django-sesame 1.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-sesame 1.3
File Size Uploaded Provenance Actions
django-sesame-1.3.tar.gz 7.3 kB Without provenance Details for django-sesame-1.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-sesame 1.3
File Interpreter ABI Platform Actions
django_sesame-1.3-py2.py3-none-any.whl Python 3, Python 2 none any Details for django_sesame-1.3-py2.py3-none-any.whl

Total release size: 18.8 kB

Release files / django-sesame-1.3.tar.gz

Download URL django-sesame-1.3.tar.gz
Size 7.3 kB
Tags Source
SHA-256 checksum
How to use checksums
10391e973627da3e45f6ea5ff073685efb11d30567aaf40c1daa8d1313ab842f
BLAKE2b-256 checksum
How to use checksums
0ea8b1e580cc656be6a0288d7e82135f496c06f2fdce4f20041b525cd2ebb12a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / django_sesame-1.3-py2.py3-none-any.whl

Download URL django_sesame-1.3-py2.py3-none-any.whl
Size 11.5 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
022079bc36edec3f3e427a5490a92261d2583d4b629220728c1de02f6cccd2d2
BLAKE2b-256 checksum
How to use checksums
664762a370d26db571969d9ae83bbfa41e9232a58ec6644a811e94aecd8196c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for django-sesame 1.3

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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