# EVE esi SSO problems. Need help retrieving token. ERR 400

**URL:** <https://forums.eveonline.com/t/eve-esi-sso-problems-need-help-retrieving-token-err-400/120820>\
**Category:** Third Party Developers\
**Created:** [November 16, 2018, 4:19am UTC](https://forums.eveonline.com/t/eve-esi-sso-problems-need-help-retrieving-token-err-400/120820 "2018-11-16T04:19:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Blackpearl](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/blackpearl/32/106732_2.png) [@Blackpearl](https://forums.eveonline.com/u/Blackpearl)\
**Post date:** [November 16, 2018, 4:19am UTC](https://forums.eveonline.com/t/eve-esi-sso-problems-need-help-retrieving-token-err-400/120820/1 "2018-11-16T04:19:09Z")

</div>

I have tried several different languages in attempt to retrieve a token. Here is what I have with PHP/c#. So the initial PHP code is used for logon, and retrieving auth code. C# is used as the client side app and retrieving the token.

**–LOGIN–** [a link to select char and get a callback, works fine.]

\<?php  
$ssourl = “[https://login.eveonline.com](https://login.eveonline.com)”;  
$callback = “[http://stuntitup.com/eve/esi/callback.php](http://stuntitup.com/eve/esi/callback.php)”;  
$urlCallback = urlencode($callback);  
$client\_id = “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”;  
$scope\_location = “esi-location.read\_location.v1”;  
$urlauth = $ssourl."/v2/oauth/authorize/?response\_type=code";  
$urlauth = $urlauth."&redirect\_uri=".$urlCallback;  
$urlauth = $urlauth."&client\_id=".$client\_id;  
$urlauth = $urlauth."&scope=".$scope\_location;  
$urlauth = $urlauth."&state=".“valid”;  
echo “\<a href=’”.$urlauth."’\>Authorize\</a\>";  
?\>

**–Call Back–** [Outputs auth code, works fine]  
\<?php  
echo code = \_REQUEST[‘code’];  
?\>

I then copy the above code, and paste it into the c# client in attempt to retrive a token.

**—Client c#—** - Different errors 40x

private void button3\_Click(object sender, EventArgs e)  
{

```
using (var client = new WebClient())
{

```

string Client\_ID = “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”;  
string Secret = “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”;  
string code = “1L6IrMZNp0-OtX32-hX6xA”; //PASTE CODE HERE

```
    string auth_header = Client_ID + ":" + Secret;
    byte[] plainTextBytes = System.Text.Encoding.UTF8.GetBytes(auth_header);
    string auth_header_64 = System.Convert.ToBase64String(plainTextBytes);
    client.Headers[HttpRequestHeader.Authorization] = "Basic " + auth_header_64;
    client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
    //client.Headers[HttpRequestHeader.Host] = "login.eveonline.com";

    // build the post parameters.
    NameValueCollection post_params = new NameValueCollection();
    post_params.Add("grant_type", "authorization_code");
    post_params.Add("code", code);
    
    // post info and grab the response.
     byte[] response = client.UploadValues("https://login.eveonline.com/oauth/token", "POST", post_params);
    
    string actual_response = Encoding.UTF8.GetString(response);
    }

```

}

The error I am getting for this one is “The remote server returned an error: (400) Bad Request”.

My thoughts are…

1. Does the ESI server complain about me using a c# client mixed with php from a different server?
2. Am I constructing the info to be sent properly?
3. Should I try yet another language? lol…

---

<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:** [November 16, 2018, 4:30am UTC](https://forums.eveonline.com/t/eve-esi-sso-problems-need-help-retrieving-token-err-400/120820/2 "2018-11-16T04:30:11Z")

</div>

Well for one, based on your code, you’re fetching the code from the v2 SSO endpoint, but POSTING it to the v1 endpoint.

---

<div class="post-metadata">

**Author:** ![Blackpearl](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/blackpearl/32/106732_2.png) [@Blackpearl](https://forums.eveonline.com/u/Blackpearl)\
**Post date:** [November 16, 2018, 4:32am UTC](https://forums.eveonline.com/t/eve-esi-sso-problems-need-help-retrieving-token-err-400/120820/3 "2018-11-16T04:32:28Z")

</div>

HAHA, oh snap. Copy and paste links got the best of me. I will have to fix that part tomorrow and see if it helps.

That worked. 🙂 TYVM! Smh… so frustrating.

---

<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:** [February 14, 2019, 4:32am UTC](https://forums.eveonline.com/t/eve-esi-sso-problems-need-help-retrieving-token-err-400/120820/4 "2019-02-14T04:32:34Z")

</div>

Closed on February 14, 2019, 4:32am UTC

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