SuLab / WikidataIntegrator

A Wikidata Python module integrating the MediaWiki API and the Wikidata SPARQL endpoint
MIT License
244 stars 46 forks source link

Oauth 1.0 usage instructions are unclear #181

Open kwisatz opened 2 years ago

kwisatz commented 2 years ago

From the README's section on OAuth1:

The method continue_oauth() will either promt the user for a callback URL (normal bot runs) or it will take a parameter so in the case of WDI being used as a backend for e.g. a web app, where the callback will provide the authentication information directly to the backend and so no copy and paste of the callback URL is required.

Two things are unclear at this point when trying to use this authentication mechanism within a script/bot:

  1. When registering an oauth consumer, which value has to be inserted for OAuth "callback" URL?
  2. When the script prompts for a callback URL (Callback URL:), which value should be inserted

considering that a script does not have a webserver to call back to.

I also checked https://www.mediawiki.org/wiki/OAuth/For_Developers#OAuth_1.0a which didn't help all too much in finding answers to those questions.

kwisatz commented 2 years ago

I understood from reading the code that I can just paste any made-up callback URL given that all that we're interested in are the query arguments. However, doing that, I got a TypeError: must be str or None, not bytes due to the use of split(b'?'). In my case, the question mark is not encoded and I had to remove the b prefix to make it work. Not sure in which case the pasted URL would be considered bytes instead of a string?

kwisatz commented 2 years ago

I stumbled upon https://www.mediawiki.org/wiki/Extension_talk:OAuthAuthentication#OAuth_%22callback%22_URL_for_OAuthAuthentication_applications just now. I haven't tried it yet though. Is that what would be recommended for WDI too?

kwisatz commented 2 years ago

I understood from reading the code that I can just paste any made-up callback URL given that all that we're interested in are the query arguments. However, doing that, I got a TypeError: must be str or None, not bytes due to the use of split(b'?'). In my case, the question mark is not encoded and I had to remove the b prefix to make it work. Not sure in which case the pasted URL would be considered bytes instead of a string?

This is still valid, and may be more pressing that the rest of this ticket.

andrawaag commented 1 year ago

Thank you for your pull request. I am restructuring the repo a bit to get a better grip on the library. Unfortunately, I am not an expert on OAUTH. Since raising the issue have you gained a better understanding? If so can I ask for another pull request?