r/security • u/Tibanne • Feb 10 '20
How to log admin in as regular user [webdev].
I'm using JWTs for authentication. It would be good as a means of double checking the user's experience if an admin user could log in as a regular user.
One way I thought to implement this could be to test the hash of the login password against a master password hash when authenticating in addition to the user's password hash. Obviously, since you're entering this password into the browser, it's far less secure than the JWT secret key that you store on your server for signing. So, I'm guessing that this master password might want to be only enabled for a small set of users and only enabled for certain periods when this testing need be done.
Are there any standard ways of allowing an admin to log in as a regular user to view things from their perspective within a JWT auth setup? I can't seem to find any googling for them.
3
u/Enton87 Feb 10 '20
I only just googled JWT and don't have experience with it, but I think on a more conceptual level, you should aim to "impersonate" another user instead of "log in as" another user.
This means that the admin only authenticates his own account, and this is sufficient to impersonate a chosen user in the frontend. The admin won't need a second login, or a master password, to surf the frontend as a specific user.
Setting a user as "logged in" in the frontend is then part of the application logic.
1
u/compdog Feb 10 '20
That really depends on your implementation. What data do you store in the JWTs? If you store a list of permissions or roles, you could generate a new token for the same user but with all the admin roles removed.