-
Notifications
You must be signed in to change notification settings - Fork 46
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
API Key and User-Agent should preferrably be passed as headers #192
Comments
Thanks for pointing these issues out, @shoeffner! I completely agree – the API Key should be included in the headers, and it looks like
The custom class seems more future-proof, especially if Dataverse introduces new authentication methods. The direct fix is quicker, but I’m leaning towards the custom class and keeping auth. As for the |
Reworking
I can't say much about the refactoring in #189, as I am not familiar with the code base in general. But I agree that using a dict for params instead of manually building up the URLs is a good idea. Let me know if I can help with anything. |
Great, that sounds like a plan! Would you be willing to open a PR for this issue? I’d be happy to help out with it. By the way, we talked about this in today’s PyDataverse Working Group meeting with @pdurbin and @donsizemore. You can watch the recording here and check out our upcoming meetings on py.gdcc.io if you'd like to join next time. For discussions outside of these meetings, we also have a Zulip channel for everything related to Python and Dataverse. |
Thanks @JR-1991, I'll take a chance implementing that.
There was not much talk about the User-Agent or params, but as @JR-1991 already mentioned that the params might become part of #189, I'll leave that part out and focus on the first step for the authentication, that is using the X-Dataverse-key header. |
Sounds perfect. Thanks, @shoeffner! ❤️ You're welcome to test against https://demo.dataverse.org Or you can run Dataverse in Docker, as mentioned in the README. |
Thanks, I'll focus on the docker-setup for the moment, and once it's done and green, I'll go for the live instance :) |
It is still possible to use the api_token parameter. In this case we assume an API token was grabbed from the user profile of a Dataverse instance. If both are specified, an api_token and an explicit auth method, we will warn the user and use the auth method. Closes gdcc#192.
It is still possible to use the api_token parameter. In this case assume an API token was copied from the user profile of a Dataverse instance. If both are specified, an api_token and an explicit auth method, warn the user and use the auth method. Closes gdcc#192.
It is still possible to use the api_token parameter. In this case assume an API token was copied from the user profile of a Dataverse instance. If both are specified, an api_token and an explicit auth method, warn the user and use the auth method. Closes gdcc#192.
It is still possible to use the api_token parameter. In this case assume an API token was copied from the user profile of a Dataverse instance. If both are specified, an api_token and an explicit auth method, warn the user and use the auth method. Closes gdcc#192.
Issue
The API key and User-Agent are currently passed as GET parameters, ideally they should be passed as headers. User-Agents are commonly passed as headers, and for the key this is actually preferred.
It also is slightly more secure, as the dataverse API will return the full request URL on error, possibly exposing API keys in logs:
(taken from datalad/datalad-dataverse#310, where I found out about this; it also contains a little bit of context)
I am not sure if this request is a bug or feature, so I decided to open a normal issue. The pyDataverse version I use is 0.3.3, and the code doing this is in pyDataverse/api.py:
pyDataverse/pyDataverse/api.py
Lines 103 to 138 in 3b6fe06
The same is done for post_request, etc.
A possible change would be to use headers and pass them as headers:
Additionally, I noticed that neither the
params
nor theauth
attributes are used.For the params a fix could be, especially after moving the key and user-agent to the headers:
For the auth parameter it's a bit more difficult, since it currently does not affect the behavior although it should.
One possible way would be to update the if statement before adding the token to the header:
However, it might make sense to change the default value to True in this case, to keep the behavior stable. However, I am not 100% sure what is the best way to handle this. Of course, one option would also be to remove the auth argument completely.
Lastly, the docstring of the function mentions the requests.Response, while it's now a httpx.Response. While they do have a similar interface, they have some minor differences; e.g., requests has an .ok property and uses iter_content, while httpx does not have .ok and uses iter_bytes.
I think I could try to "fix" this and draft a PR.
The text was updated successfully, but these errors were encountered: