[SOLVED] Unknown grant_type: 'authorization_code'


(Nomadicca) #1

SOLUTION: I was using the wrong Content-Type

  • I had x-www-form-urlencoded should (for this snippet) be json

I am working on a local copy of an app and am getting a 400 response code with “Unknown grant_type”.

I have done some googling and only references to this that I found were because the grant_type was actually wrong. This is not the case in my code. I have seen some other posts about this as well but for other auth paths that weren’t similar enough to get a resolution from.

Any help / suggestions are very much appreciated.

I am using Node.js with requests module installed. Code is below:
(ID:SECRET string is redacted)

request.post({
            url: "https://login.eveonline.com/oauth/token",
            headers: {
                "Content-Type": "application/x-www-form-urlencoded",
                "Authorization": "Basic id:secret"
            },
            body: JSON.stringify({
                "grant_type": "authorization_code", //line that seems to be generating the error
                "code": code
            }),
        },
        function(e, r, b) {
            if (e) {
                console.log("An Error");
                console.log(e);
            } else {
                console.log(b);
            }
        }
    );

(Blacksmoke16) #2

Are you base64 encoding your ID:SECRET string?

If so it just sounds like the requests lib isn’t making the request correctly. Could you give a sample of what the request looks like from the browser?


(Nomadicca) #3

I used btoa to encode the string (first thing i found). Is there a better method?

The request fails with a 404 when working from a browser (since POST I think) but in Postman (Chrome App) it works fine. Postman generates the code but is using XMLHTTPRequest.


(Blacksmoke16) #4

If the string you got from btoa works in Postman then that wouldn’t be the issue i would think.

Oh.

Try changing your Content-Type header to application/json


(Nomadicca) #5

Worked a treat!

Thanks a million (because I’m spacepoor) :smiley:


(Blacksmoke16) #6

NP :slight_smile:


(system) #7

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.