kaimallea / node-imgur

Upload images to imgur.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bad request 400 with album

pers912369 opened this issue Β· comments

If I want to upload and image with a given url I don't have any problem, but, if I provide an album I get a response 400 (Bad Request) from node_modules\got\dist\source\as-promise\index.js:117:42.

First, I thought that it was a credentials issue, instead of using imgur.setClientId(clientId) i used imgur.setCredentials(email, password, clientId) but with this I get RequestError: Missing url property from node_modules\got\dist\source\core\index.js:1372:21

@pers912369 Are you able to make a change to the node-imgur package to see if it resolves your issue?

On this line, 147 in node_modules/node-imgur/lib/imgur.js, https://github.com/kaimallea/node-imgur/blob/main/lib/imgur.js#L147

Change "uri" to "url"

    uri: 'https://api.imgur.com/oauth2/authorize',

to

    url: 'https://api.imgur.com/oauth2/authorize',

And then test your upload again? If you are able to confirm whether or not this resolves your issue, I think that would be fastest. I will work on an example to reproduce your case in the meantime.

@pers912369 Are you able to make a change to the node-imgur package to see if it resolves your issue?

On this line, 147 in node_modules/node-imgur/lib/imgur.js, https://github.com/kaimallea/node-imgur/blob/main/lib/imgur.js#L147

Change "uri" to "url"

    uri: 'https://api.imgur.com/oauth2/authorize',

to

    url: 'https://api.imgur.com/oauth2/authorize',

And then test your upload again? If you are able to confirm whether or not this resolves your issue, I think that would be fastest. I will work on an example to reproduce your case in the meantime.

@KenEucker I don't know why but i compared some lines from [https://github.com/kaimallea/node-imgur/blob/main/lib/imgur.js] and my file and they're not the same, the "uri" property is not in line 147, in my file is in 175. And yes, before anyone asks, i have the latest version(0.3.2).

With that change instead of getting a 400 error i get
RequestError: Unexpected token < in JSON at position 0 in "https://api.imgur.com/oauth2/authorize?client_id=MY_CLIENT_ID&response_type=token"

I think the bigger issue is that the Imgur API appears to no longer support the Resource Owner Password Credentials Grant type (i.e., you provide your username/password and get back an access token). Instead, they now enforce the Authorization Code Grant type. This means that in order to retrieve an access token, authorization must be done in a browser, and a server is required to handle the redirect/callback and extract the token from the location hash.

TL;DR you must perform this flow separately and then provide the module with the access token. We'll probably remove that code altogether that is breaking for you since Imgur no longer supports it.

@kaimallea is that true?

If so, I imagine that this would be the ordinary way in which people use the current API. I do obtain an access token in the way you describe, which results in a bearer token, but I've also felt like my use case was outside of the normal usage of this package.

The reason I had implemented #114 was because I use that functionality in my project to incorporate that authentication flow. If what you're saying is true, that seems to be a major breaking change.

Also, if that is true today then users must already be experiencing an inability to use the current imgur API with a username and password. We should test for this. Is there an opportunity to include a replacement for the mocks that runs tests with real credentials, or whatever credentials required end up being?

Actually if i open the url that the error gives "https://api.imgur.com/oauth2/authorize?client_id=MY_CLIENT_ID&response_type=token" it shows in my browser an authorization dialog, but i don't know why after clicking to allow my application nothing happens.

@KenEucker you're 100% right and I'm 100% wrong. Idk why I would think Imgur would remove their own login flow. Apparently, when I get sleep, I think a little clearer. πŸ˜„ I think I know what the problem is, probably related to the way got works versus request re: redirects. Incoming PR after I run a quick experiment.

@pers912369 stay tuned for fix

@pers912369 unless you have a server managing your auth flow and your host configured as the imgur auth callback. That url login from the browser won't know how to complete the auth.

@kaimallea all good. I'm relieved to hear that this auth flow will still work for people. I think it's nice that Imgur offers it. I know that it is not a common auth strategy these days.

πŸŽ‰ This issue has been resolved in version 1.0.0 πŸŽ‰

The release is available on:

Your semantic-release bot πŸ“¦πŸš€