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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file django-impersonator-0.0.2.tar.gz.

File metadata

  • Download URL: django-impersonator-0.0.2.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for django-impersonator-0.0.2.tar.gz
Algorithm Hash digest
SHA256 b77d69c26219cec9d7b0f644c0de4f5bdcf9afa35d55ce16f9c8daa9079c56b3
MD5 c6f7a03706fa829f1e6d6857c4cb1059
BLAKE2b-256 639712601965d9396d603a3f2334f6d8b951d8e2ada4194bb875ca0808d5c092

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_impersonator-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a98e6eaed72be83cc44f95ef270e403766fcb6894de22d9037e8b3f03d2542b5
MD5 bef3b9f4a92cd2da1e04a5a65a7fcf0b
BLAKE2b-256 ba8e568e027d632b4fa9258c9c1cc15c729217900356c29cf14a4d601526d956

See more details on using hashes here.

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