-
Notifications
You must be signed in to change notification settings - Fork 187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No user_id is recorded #165
Comments
I think that's a fairly accurate statement. Will accept PR to change that. We do support general usage of the login_user signal (e.g. manually telling Django, and I've seen that work for JWT login via DRF hooks). If there is a way for the library to more seamlessly hook into the general system, that would be good. Note: that is only for login. Once logged in, easy audit model signals will otherwise grab the user via it's Middleware. Curious which version of django and python? If django 3.1, async or sync views/Middleware? Easy audit only uses sync Middleware (which should be fine and we have unit tests). |
@hasahmad did you find a workaround? I am having the same issue? |
@hasahmad, I posted this on behalf of one of my clients. The issue was due to him not authenticating some requests. Simply fixing some calls he was making anonymously fixed this issue(and a security hole he had) |
What do you mean by that '... not authenticating some requests. Simply fixing some calls ...'? My project uses a lot of interconnected models and most (if not all) are exposed through authenticated ViewSets using the DRF's Are you able to provide some detail about what he did specifically? |
Which DRF authentication classes are you using in your project? |
I just tested it with Edit: It does work for CRUD events, though. |
Turns out that there are already some solutions, unfortunately in DRF so everyone could benefit from them. One of them is DRF JWT: jpadilla/django-rest-framework-jwt#45 (comment) Basically, DRF authenticates in the view layer. The workaround is to supply a custom middleware that does the authentication. However, it leads to authenticating twice and thus increasing the number of DB queries. I looked at how the request is logged in this plugin (see https://github.com/soynatan/django-easy-audit/blob/master/easyaudit/signals/request_signals.py#L38). I wonder whether instead the What do you think @jheld? |
For reference, the django docs on the I'm not sure that I fully understand whether the DRF JWT snippet in the link solved the problem, but regarding this library, I'm open to accepting some changes, like:
@mschoettle how does the above sound, or did I miss something? |
@jheld: Took me a while to get back to this. I am playing around with the signals and
So it seems that handling requests in It looks like this would solve a few of the issues reported. What do you think? Update: Did a quick test where I moved the request started signal handler code into the middleware. def __call__(self, request: WSGIRequest):
self.process_request(request)
# gather request data
response = self.get_response(request)
# get user from request.user
audit_logger.request(...)
self.process_response(request, response)
return response Based on preliminary results this works. I can create a PR for this for review @jheld. |
I am using this with Django rest framework, using OAuth2, and it's not recording
user_id
Are you only checking for users in session cookie?
The text was updated successfully, but these errors were encountered: