Skip to main content

Impersonate middleware to let you impersonate other users.

Project description

django-impersonate

This Django app lets admin users impersonate other users, useful when testing and debugging permissions.

Non superusers are not allowed to perform this request, even if they have view rights to the User model, so that this cannot be used for privilege escalation.

As admin, I can choose the "Impersonate" action:

image

Impersonations are terminated by closing the bottom left pop-up.

image

Impersonate is not available for regular users, returning an error for those with view rights to the User model.

Setup

Add middleware to your middleware list and make sure it comes after django.contrib.auth.middleware.AuthenticationMiddleware:

MIDDLEWARE = [
    ...
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    ...
    'impersonate.middleware.ImpersonateMiddleware',
    ...
]

In one of your admin.py files, add the action to UserAdmin (or the admin model of your custom User)

from impersonate.admin import impersonate_action
from django.contrib.auth import admin


admin.UserAdmin.actions.append(impersonate_action)

Or call it from any of your views (if you're not using django-admin)

from django.contrib.auth import models
from impersonate.admin import impersonate_action

def my_view(request, target_username):
    return impersonate_action(None, request, models.User.objects.filter(username=target_username))

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_impersonator-0.0.3.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_impersonator-0.0.3-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file django_impersonator-0.0.3.tar.gz.

File metadata

  • Download URL: django_impersonator-0.0.3.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for django_impersonator-0.0.3.tar.gz
Algorithm Hash digest
SHA256 3a8a9a7af675c213abada1eb4583dc527d4a6f574610c463c833723ff8ca9924
MD5 c2a2e406a777860ff39450ba8423aa8c
BLAKE2b-256 fb1188a5ff7c545bc6cf2386cec161a73f62b5447d4aa080eec3c557a75ae179

See more details on using hashes here.

File details

Details for the file django_impersonator-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for django_impersonator-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 02bb367b645c06f3d33875e48dc5f84764c47f8f34d8fa041b31eeb79d097ad6
MD5 3b2641b26bc5450ec5ed043b76ecde25
BLAKE2b-256 fa1203d75ba7dd5d4cc0188b79762bb2d81e72959ccd2f0de2bf8da93ebfe777

See more details on using hashes here.

Supported by

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