# C# SSO call gives 400 when I try to get a token

**URL:** <https://forums.eveonline.com/t/c-sso-call-gives-400-when-i-try-to-get-a-token/185833>\
**Category:** Third Party Developers\
**Created:** [August 26, 2019, 10:06am UTC](https://forums.eveonline.com/t/c-sso-call-gives-400-when-i-try-to-get-a-token/185833 "2019-08-26T10:06:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tanaka\_Seiko](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/tanaka_seiko/32/439667_2.png) [@Tanaka\_Seiko](https://forums.eveonline.com/u/Tanaka_Seiko)\
**Post date:** [August 26, 2019, 10:06am UTC](https://forums.eveonline.com/t/c-sso-call-gives-400-when-i-try-to-get-a-token/185833/1 "2019-08-26T10:06:10Z")

</div>

Hey guys,

I am stuck here. This should work, but I get a http 400 instead of a token. I really ould like to work through this and understand the mechanics myslef instead of using a library. Do i do anything wrong here? See code:

```
 private void GetToken(String codeStr)
    {
        WebClient request = new WebClient();
                             
        string auth_header = $"{clientID}:{secretKey}";
        string auth_header_64 = $"Basic {Convert.ToBase64String(Encoding.UTF8.GetBytes(auth_header))}";
        request.Headers[HttpRequestHeader.Authorization] = auth_header_64;
        var post_params = new NameValueCollection();
        post_params.Add("grant_type", "authorization_code");
        post_params.Add("code", codeStr);

        byte[] response = request.UploadValues($"https://login.eveonline.com/oauth/token", "POST", post_params);
        string actual_response = Encoding.UTF8.GetString(response);

        MessageBox.Show(actual_response);
    }
```

---

<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:** [August 26, 2019, 12:04pm UTC](https://forums.eveonline.com/t/c-sso-call-gives-400-when-i-try-to-get-a-token/185833/2 "2019-08-26T12:04:56Z")

</div>

Try setting a `Content-Type: application/x-www-form-urlencoded` header and making sure your values are properly escaped.

Also, whats the error you get back?

---

<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:** [November 24, 2019, 12:04pm UTC](https://forums.eveonline.com/t/c-sso-call-gives-400-when-i-try-to-get-a-token/185833/3 "2019-11-24T12:04:56Z")

</div>

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