Styria-Digital / django-rest-framework-jwt

JSON Web Token Authentication support for Django REST Framework
https://styria-digital.github.io/django-rest-framework-jwt/
MIT License
192 stars 60 forks source link

Impersonation Token #103

Open NiraliSupe opened 3 years ago

NiraliSupe commented 3 years ago

Hello,

Thank you for the awesome token authentication plugin.

I need to implement the api where super user can become anyone and debug the issue. I found the documentation on the token impersonation, however, It doesn't explain much on how to setup the api. Could you please provide more details on the same preferably example?
https://styria-digital.github.io/django-rest-framework-jwt/#impersonation-token

Please let me know if you need anything else.

Thank you

creyD commented 2 years ago

This is properly documented, you just need to add from rest_framework_jwt.views import impersonate_jwt_token and a path to this to your urls.py and then you can sent a package with {'user': <USER_ID>} to the endpoint and you get an authentication token for the user with the USER_ID. Only works as a Django superuser of cause. If you need to make any adjustments to this config you can overwrite it at any point (Serializer, View etc).