You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm working on the QGIS GeoNode plugin, hoping to implement upload of new datasets to GeoNode from whithin QGIS.
Unfortunately it seems to not be possible to use the GeoNode REST API to perform upload of files. This seems to be due to the REST API uploads following the same code path that was originally implemented for the django-based GUI.
The problem is that logged_in_or_basicauth tries to get the current user by calling django.contrib.auth.get_user(request) (find it here in the django docs) and fails because it cannot find the user. As mentioned in the linked documentation above, django.contrib.auth.get_user() tries to use the current django session to get the user. This cannot be applied in the context of the REST API, since it does not use sessions.
Steps to Reproduce the Problem
In order to reproduce this, you'd need to setup a dev instance of GeoNode, then configure an oauth application, then try to upload some sample file using the /api/v2/uploads/upload/ API endpoint. This is not a trivial setup though. This is the oauth2 config I am using:
Note that for now I'm using the Resource owner password-based authorization flow, which simplifies development. This is not related to the current issue though, as I have previously verified that this auth mode works OK when accessing other API endpoints.
Then I'm using the following code to get an access token and then perform an upload POST request:
The code above returns an HTTP status of 401 Unauthorized. I've been going through the code and found that this is generated by the aforementioned decorator function - the GeoNode view never gets to process the request.
The fix for this seems simply a matter of replacing auth.get_user(request).is_authenticated with req.user.is_authenticated in the logged_in_or_basicauth and geonode.upload.views.view().
I haven't actually tried this change yet but I'm willing to test it and submit a PR with it
Ok @ricardogsilva let us know if the fix works.
It's good to see the Oauth2 based flow implemented. However, can you confirm that also a more simpler basic auth also works?
I'm working on the QGIS GeoNode plugin, hoping to implement upload of new datasets to GeoNode from whithin QGIS.
Unfortunately it seems to not be possible to use the GeoNode REST API to perform upload of files. This seems to be due to the REST API uploads following the same code path that was originally implemented for the django-based GUI.
I've traced down the problem to the decorator logged_in_or_basicauth(). This decorator is being applied to the geonode.upload.views.view() function, which is what the REST API is calling into.
The problem is that
logged_in_or_basicauth
tries to get the current user by callingdjango.contrib.auth.get_user(request)
(find it here in the django docs) and fails because it cannot find the user. As mentioned in the linked documentation above,django.contrib.auth.get_user()
tries to use the current django session to get the user. This cannot be applied in the context of the REST API, since it does not use sessions.Steps to Reproduce the Problem
In order to reproduce this, you'd need to setup a dev instance of GeoNode, then configure an oauth application, then try to upload some sample file using the
/api/v2/uploads/upload/
API endpoint. This is not a trivial setup though. This is the oauth2 config I am using:Note that for now I'm using the
Resource owner password-based
authorization flow, which simplifies development. This is not related to the current issue though, as I have previously verified that this auth mode works OK when accessing other API endpoints.Then I'm using the following code to get an access token and then perform an upload POST request:
The code above returns an HTTP status of
401 Unauthorized
. I've been going through the code and found that this is generated by the aforementioned decorator function - the GeoNode view never gets to process the request.Specifications
The text was updated successfully, but these errors were encountered: