# Can't get token from SSO - Grant type authorization\_code is not supported

**URL:** <https://forums.eveonline.com/t/cant-get-token-from-sso-grant-type-authorization-code-is-not-supported/348167>\
**Category:** Third Party Developers\
**Created:** [February 2, 2022, 1:57pm UTC](https://forums.eveonline.com/t/cant-get-token-from-sso-grant-type-authorization-code-is-not-supported/348167 "2022-02-02T13:57:44Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Akida\_Ohaya](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/akida_ohaya/32/414508_2.png) [@Akida\_Ohaya](https://forums.eveonline.com/u/Akida_Ohaya)\
**Post date:** [February 2, 2022, 1:57pm UTC](https://forums.eveonline.com/t/cant-get-token-from-sso-grant-type-authorization-code-is-not-supported/348167/1 "2022-02-02T13:57:44Z")

</div>

Hello there friends,

So i’m working on a tool and i need to gather assets and jobs from my character.

I’m following docs/sso/web\_based\_sso\_flow.html

I was able to get the code from /v2/oauth/authorize/ and have it properly stored.

Now i’m just trying to get the token with it and i keep receiving authorization\_code is an invalid grant type which makes no sense.

I searched the forums and tried changing a lot of stuff. The Content-Type header and the body formating and nothing seems to work

I’m using Laravel( PHP ) and Guzzle to develop my solution.

When i use guzzle debugging the request goes like this:

> POST /v2/oauth/token HTTP/1.1 Host: login. eveonline .com Accept: application/json Authorization: Basic PROPERLY\_ENCODED\_CLIENT\_SECRET User-Agent: GuzzleHttp/7 Content-Type: application/x-www-form-urlencoded Content-Length: 57 \* upload completely sent off: 57 out of 57 bytes \* old SSL session ID is stale, removing \* Mark bundle as not supporting multiuse

My request is quite simple with the authorization header already being calculated and added on the instantiation.

 ![image](https://global.discourse-cdn.com/eveonline/original/4X/b/6/8/b6888e305fb3bfea21f374f5243a6311c12b997a.png)

The authorization seems to be working because if remove the authorization header it gives me 401 instead of 400.

I’ve also used postman to test this but get the same problem.  
The curl reads as:  
curl --request POST ‘https:// login. eveonline .com/v2/oauth/token’   
–header ‘Authorization: Basic PROPERLY\_ENCODED\_CLIENT\_SECRET’   
–header ‘Host: [login.eveonline.com](http://login.eveonline.com)’   
–header ‘Content-Type: application/x-www-form-urlencoded’   
–header ‘Cookie: \_\_cf\_bm=vw.YOARQUa2yX8X7ZfaNUrp9x63e8Ct5GXXEfUDwS30-1643808566-0-AUsQXPwBxhYUusb7reYq6vfwlq0KTo8aOwnKmbmWRZ0Uu1tylhgFFbp/+uZjeGW4Iq/4RgIFh5wvI1777IM9BcWt3Jh7H+9CH1yM2tiWgM12; lang=en’   
–data-urlencode ‘grant\_type=authorization\_code’   
–data-urlencode ‘code=SECRET\_CODE’

So the error seems to be definitely on the body but what am i doing wrong?

---

<div class="post-metadata">

**Author:** ![Akida\_Ohaya](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/akida_ohaya/32/414508_2.png) [@Akida\_Ohaya](https://forums.eveonline.com/u/Akida_Ohaya)\
**Post date:** [February 2, 2022, 1:58pm UTC](https://forums.eveonline.com/t/cant-get-token-from-sso-grant-type-authorization-code-is-not-supported/348167/2 "2022-02-02T13:58:34Z")

</div>

Had to split some URL’s there because apparently im a new user.  
Please account for that if you copy the curl request.

---

<div class="post-metadata">

**Author:** ![Rihan\_Shazih](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/rihan_shazih/32/406992_2.png) [@Rihan\_Shazih](https://forums.eveonline.com/u/Rihan_Shazih)\
**Post date:** [February 2, 2022, 2:15pm UTC](https://forums.eveonline.com/t/cant-get-token-from-sso-grant-type-authorization-code-is-not-supported/348167/3 "2022-02-02T14:15:50Z")

</div>

> [@Akida\_Ohaya](#):
>
> So the error seems to be definitely on the body but what am i doing wrong?

I see that you have `data-urlencode` twice. Without knowing how postman works, I’d suggest moving that into one line.

Your PHP code looks fine though, so that’s probably not the issue.

Here’s the code I’m using (ES6, TS). The only difference I see is the `Accept` header.

```auto
await axios.post(`https://login.eveonline.com/v2/oauth/token`, `grant_type=authorization_code&code=${code}`, {
            headers: {
                Authorization: `Basic ${Buffer.from(`${esiKey}:${esiSecret}`).toString('base64')}`,
                'Content-Type': 'application/x-www-form-urlencoded',
                Host: 'login.eveonline.com',
                Accept: 'application/json',
            }
        });

```

---

<div class="post-metadata">

**Author:** ![Akida\_Ohaya](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/akida_ohaya/32/414508_2.png) [@Akida\_Ohaya](https://forums.eveonline.com/u/Akida_Ohaya)\
**Post date:** [February 2, 2022, 3:01pm UTC](https://forums.eveonline.com/t/cant-get-token-from-sso-grant-type-authorization-code-is-not-supported/348167/4 "2022-02-02T15:01:51Z")

</div>

Added the accept header and nothing changed.  
Same error.

Also tried the manually using curl on the terminal with one data-urlencode.

Also tried both again with a new code without success.

@Rihan_Shazih could you post a working CURL for me? With obfuscated data of course.

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/blacksmoke16/32/376589_2.png) [@Blacksmoke16](https://forums.eveonline.com/u/Blacksmoke16)\
**Post date:** [February 2, 2022, 4:03pm UTC](https://forums.eveonline.com/t/cant-get-token-from-sso-grant-type-authorization-code-is-not-supported/348167/5 "2022-02-02T16:03:35Z")

</div>

Can you share _how_ you’re getting your authorization code? Like are you sure you’re not doing the implicit flow and getting a token instead of the authorization code?

---

<div class="post-metadata">

**Author:** ![Akida\_Ohaya](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/akida_ohaya/32/414508_2.png) [@Akida\_Ohaya](https://forums.eveonline.com/u/Akida_Ohaya)\
**Post date:** [February 2, 2022, 4:58pm UTC](https://forums.eveonline.com/t/cant-get-token-from-sso-grant-type-authorization-code-is-not-supported/348167/6 "2022-02-02T16:58:30Z")

</div>

> **[OAuth 2.0 for Web Based Applications](https://docs.esi.evetech.net/docs/sso/web_based_sso_flow.html)**
>
> The official repository for ESI documentation

I’m following this doc.

Everything happens fine until the actual /token interaction.

Is there anything you want to know specifically?

It don’t seem like i received a JWT token.

This is an sample

QUERY PARAMETERS

**code:** lKg1BH6lv0A2uKYgNtTcCT

**state:** c444a767-c8af-4f23-a5cd-49e3d0ca3c77

---

<div class="post-metadata">

**Author:** ![Rihan\_Shazih](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/rihan_shazih/32/406992_2.png) [@Rihan\_Shazih](https://forums.eveonline.com/u/Rihan_Shazih)\
**Post date:** [February 2, 2022, 5:13pm UTC](https://forums.eveonline.com/t/cant-get-token-from-sso-grant-type-authorization-code-is-not-supported/348167/7 "2022-02-02T17:13:15Z")

</div>

He shared that above. The call to `/token` will yield and authorization token and a refresh token.

---

<div class="post-metadata">

**Author:** ![Rihan\_Shazih](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/rihan_shazih/32/406992_2.png) [@Rihan\_Shazih](https://forums.eveonline.com/u/Rihan_Shazih)\
**Post date:** [February 2, 2022, 5:14pm UTC](https://forums.eveonline.com/t/cant-get-token-from-sso-grant-type-authorization-code-is-not-supported/348167/8 "2022-02-02T17:14:55Z")

</div>

@Akida_Ohaya Just to be sure, can you show us your code when you also pass the Authorization header? Feel free to redact it, just want to be sure that it’s set up correctly. I don’t see it in the picture of `getAuthorizationToken` yet.

---

<div class="post-metadata">

**Author:** ![Akida\_Ohaya](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/akida_ohaya/32/414508_2.png) [@Akida\_Ohaya](https://forums.eveonline.com/u/Akida_Ohaya)\
**Post date:** [February 2, 2022, 5:24pm UTC](https://forums.eveonline.com/t/cant-get-token-from-sso-grant-type-authorization-code-is-not-supported/348167/9 "2022-02-02T17:24:38Z")

</div>

The header is set on the constructor. I use a very simple wrapper on guzzle to add basic config and logging.

The Guzzle debug output the header properly.

 ![image](https://global.discourse-cdn.com/eveonline/original/4X/1/c/6/1c6d21113a10805d17359e10d08d2343c1b13d29.png)

I have the base64 value preprocessed.  
I did like CLIENT\_ID:CLIENT\_SECRET then saved on an env file.

---

<div class="post-metadata">

**Author:** ![Rihan\_Shazih](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/rihan_shazih/32/406992_2.png) [@Rihan\_Shazih](https://forums.eveonline.com/u/Rihan_Shazih)\
**Post date:** [February 2, 2022, 5:29pm UTC](https://forums.eveonline.com/t/cant-get-token-from-sso-grant-type-authorization-code-is-not-supported/348167/10 "2022-02-02T17:29:25Z")

</div>

That looks fine to me. The only problem I can think of is that there’s a problem with the Authorization header value. 401 sounds to me like eve can’t recognize who you are, indicating that it can’t map the header to a client id and secret that is in its database.

When you construct an Authorization header for `CLIENT_ID_123` and `SECRET_456`, do you get `Basic Q0xJRU5UX0lEXzEyMzpTRUNSRVRfNDU2`? Sorry for being a nitpick here, just want to make sure that this is not the problem 🙂

---

<div class="post-metadata">

**Author:** ![Akida\_Ohaya](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/akida_ohaya/32/414508_2.png) [@Akida\_Ohaya](https://forums.eveonline.com/u/Akida_Ohaya)\
**Post date:** [February 2, 2022, 5:34pm UTC](https://forums.eveonline.com/t/cant-get-token-from-sso-grant-type-authorization-code-is-not-supported/348167/11 "2022-02-02T17:34:49Z")

</div>

Im getting 400 for the /token issue.  
Sorry if i wrote in a confusing way.  
I was getting the authentication wrong before and getting 401 but i solved that and started receiving 400.  
Well at least i thought i had solved it.

I ran the base64 on what you asked and got: Q0xJRU5UX0lEXzEyMzpTRUNSRVRfNDU2  
Im using [https://www.base64url.com/](https://www.base64url.com/) and getting the base64 URL one.

---

<div class="post-metadata">

**Author:** ![Akida\_Ohaya](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/akida_ohaya/32/414508_2.png) [@Akida\_Ohaya](https://forums.eveonline.com/u/Akida_Ohaya)\
**Post date:** [February 3, 2022, 1:56pm UTC](https://forums.eveonline.com/t/cant-get-token-from-sso-grant-type-authorization-code-is-not-supported/348167/12 "2022-02-03T13:56:01Z")

</div>

Ok so i redid the whole enchilada and discovered that even though the error changed from 401 to 400 the error was STILL inside the header.

I got a knack about how i was getting the error on postman, terminal curl and the application and started using php base64\_encode instead of preprocessing the basic value header and voila.

Got 200 and a token.

So i guess the lesson here is triple check base64 generation and the form body if you are getting this.

---

<div class="post-metadata">

**Author:** ![Tonto\_Auri](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/tonto_auri/32/388339_2.png) [@Tonto\_Auri](https://forums.eveonline.com/u/Tonto_Auri)\
**Post date:** [February 4, 2022, 5:27pm UTC](https://forums.eveonline.com/t/cant-get-token-from-sso-grant-type-authorization-code-is-not-supported/348167/13 "2022-02-04T17:27:53Z")

</div>

Keep in mind that there’s [more than one “base64” encoding variant](https://en.wikipedia.org/wiki/Base64#Variants_summary_table), and PHP only implement one. You’d have to `strtr()` the results sometimes to massage it into working fashion.

---

<div class="post-metadata">

**Author:** ![Akida\_Ohaya](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/akida_ohaya/32/414508_2.png) [@Akida\_Ohaya](https://forums.eveonline.com/u/Akida_Ohaya)\
**Post date:** [February 4, 2022, 6:22pm UTC](https://forums.eveonline.com/t/cant-get-token-from-sso-grant-type-authorization-code-is-not-supported/348167/14 "2022-02-04T18:22:28Z")

</div>

@Tonto_Auri Could you provide a bit more information when that should happen?

I used the default function and PHP already does it URL safe. At least seems to be the encoding expected by Eve ESI.  
I’m now able to properly query the token.

I couldn’t think of a situation where i need to do that.  
To me either the encode does it and it is on the right encoding or i need to search another encoding function.

I’m not opposed to do one myself but this is very basic and widespread. There is a function for every RFC for sure already done.  
Now re-parsing it after encoding seems a bit of both but i didn’t understand the use case.

---

<div class="post-metadata">

**Author:** ![Tonto\_Auri](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/tonto_auri/32/388339_2.png) [@Tonto\_Auri](https://forums.eveonline.com/u/Tonto_Auri)\
**Post date:** [February 6, 2022, 12:04pm UTC](https://forums.eveonline.com/t/cant-get-token-from-sso-grant-type-authorization-code-is-not-supported/348167/15 "2022-02-06T12:04:34Z")

</div>

> [@Akida\_Ohaya](#):
>
> At least seems to be the encoding expected by Eve ESI.

Then that’s all you need. I wasnt’ so lucky in my past projects \>.\>

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/eveonline/original/3X/4/1/41ec4921cbaca7a6f9ea556e7cc20018461eae5e.png) [@system](https://forums.eveonline.com/u/system)\
**Post date:** [May 7, 2022, 12:05pm UTC](https://forums.eveonline.com/t/cant-get-token-from-sso-grant-type-authorization-code-is-not-supported/348167/16 "2022-05-07T12:05:22Z")

</div>

Closed on May 7, 2022, 12:05pm UTC

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