tremby / imgur.sh

Bart's Imgur uploader bash script
The Unlicense
215 stars 35 forks source link

Tie upload to a given account #16

Open jpmvferreira opened 5 years ago

jpmvferreira commented 5 years ago

Hi there,

I was using this tool and it works as expected, did some changes, and realized it would be easier for me if the uploaded content were to be tied to my account.

Using the imgur API i have registered an app, and got my client id, which i changed in the script field default_client_id, however when checking my imgur account the image is not there, and i would like it to.

After reading the imgur API i got a feeling that i required a field named default_client_secret in the script, but there is none and i'm unsure how to do this authentication by myself.

Hopefully i'm not missing anything obvious and bothering you for no relevant reason.

Thanks in advance!

tremby commented 5 years ago

I'm afraid I don't personally have any interest in this feature.

Yes, the client ID is just to do with the app. Things uploaded by that app aren't specifically tied to your user account, as you've found.

I had a glance at the docs and it looks like it'd require adding support for OAuth2. That seems like it'd be a little awkward for a CLI program but I'm sure it's possible. I imagine it could work this way:

  1. We check for existing authorization info, which has perhaps been stored in a cache file.
    1. If found
      1. If it's still valid, we use that and exit
      2. Otherwise, if it can still be refreshed, we refresh, then use the new token, and exit
  2. We generate a URL (at Imgur) the user has to go to to authorize.
  3. We start a small localhost webserver to listen for the authorization callback.
  4. We either present the URL to the user or open their browser for them (like with sensible-browser).
  5. The user authorizes.
  6. We have registered the app with a localhost callback URL, so once authorization is finished the browser hits a localhost URL with the response. This is our little server started in step 3.
  7. We store the authorization information
  8. We shut down the web server
  9. We use the auth information and proceed with the request

So... doable, but it'd make the script a whole lot more complicated.

If there's a simpler way than all the above I'll merge a patch for it. But I think any working solution in Bash would have too many dependencies or be too long to be in scope for this script.

jpmvferreira commented 5 years ago

I've only suggested this feature as i am currently using another piece of software name (imgur-screenshot)[https://github.com/jomo/imgur-screenshot] which features uploading to a given account.

Honestly i have no idea how hard it is to make this work in your script, and i haven't got enough bash skills to try and do it myself, but i think it would be a nice feature to have in your script.

Hopefully the software i sent you changes your mind, or realize it's in fact too complicated to implement.

Thanks anyways!

tremby commented 5 years ago

OK, that other script employs an authorization method which doesn't need the callback, which does simplify things significantly. I didn't see that mentioned in the Imgur API documentation but perhaps I overlooked it.

We wouldn't be able to copy the relevant parts of code directly, or I'd have relicence this script under MIT, which I'd rather not do.

But it shows it's possible and not as complicated as I thought, so I'd accept this feature into this script.

I'd accept a patch if someone has the inclination, or I'll do it myself if I do find I want this feature at some point.

For now I'll leave this open. Thanks for pointing out that other script.

jpmvferreira commented 5 years ago

No problem, always glad to help however i can!

Darkmaster006 commented 2 years ago

Just chiming in and saying I would love for this feature to be available. This script is the simplest one to upload to imgur that I've found and this feature is the only thing missing for me. Either way, thank you.

takesnodamage commented 1 year ago

+1. I'm trying to upload a list of image links to an imgur album so I have to somehow associate the script with my account. I'll take a look at the jomo script but I'm far from an expert in API stuff so if this option ever did get folded into this code it would be useful.