# ESI Refresh Token 400 Bad Request

**URL:** <https://forums.eveonline.com/t/esi-refresh-token-400-bad-request/427381>\
**Category:** Third Party Developers\
**Created:** [November 12, 2023, 11:07am UTC](https://forums.eveonline.com/t/esi-refresh-token-400-bad-request/427381 "2023-11-12T11:07:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thumiel\_Zaul](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/thumiel_zaul/32/393969_2.png) [@Thumiel\_Zaul](https://forums.eveonline.com/u/Thumiel_Zaul)\
**Post date:** [November 12, 2023, 11:07am UTC](https://forums.eveonline.com/t/esi-refresh-token-400-bad-request/427381/1 "2023-11-12T11:07:27Z")

</div>

Hi App Developers, I have returned to an old code set from '22 and found an issue with refresh auth tokens.

I am getting a 400 bad request with the inner exception “Invalid Refresh Token, Unable to migrate grant.”.

I understand that refresh token values may change between grants but the weird part is I am taking the refresh token from freshly completed authentication, so the token should not have changed as I have just received it.

Here is the method I am using for token refresh, using C#.

```auto
public async Task<AuthToken> refreshToken(string _clientId, string _refreshToken)
        {
            AuthToken token;
            string authenticationUrl = tokenURL;
            HttpClient client = new HttpClient();
            HttpRequestMessage request = new HttpRequestMessage();
            string content;
            try
            {
                //set the request message
                request.Method = HttpMethod.Post;
                request.RequestUri = new Uri(authenticationUrl);
                request.Headers.Add("Host", "login.eveonline.com");

                //create content string
                content = string.Concat("grant_type=refresh_token",
                    "&refresh_token=", _refreshToken,
                    "&client_id=", _clientId);

                //parse content to HTTP content
                HttpContent postBody = new StringContent(content, Encoding.UTF8, "application/x-www-form-urlencoded");

                //set content
                request.Content = postBody;
                
                //send request
                var result = await client.SendAsync(request);

                //output result.
                var output = await result.Content.ReadAsStringAsync();

                if(result.StatusCode == HttpStatusCode.OK)
                {
                    Core.log("Token refresh successful, saving token...", Core.LogType.Information);
                    token = deserializeToken(output);
                    tokenValidFrom = DateTime.Now;
                    Core.log("Token saved...", Core.LogType.Information);
                    return token;
                }
                else
                {
                    Core.log(String.Concat("Token refresh failed with satus : '", result.StatusCode.ToString()), Core.LogType.Error);
                    return null;
                }
            }
            catch(Exception ex)
            {

                Core.log(String.Concat("Token refresh failed with exception : '", ex.ToString()), Core.LogType.Error);
                return null;
            }
        }

```

Any help would be greatly appreciated as I have read and re-read the ESI docs till my eyes bleed and I cannot see an issue 🙂

---

<div class="post-metadata">

**Author:** ![Thumiel\_Zaul](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/thumiel_zaul/32/393969_2.png) [@Thumiel\_Zaul](https://forums.eveonline.com/u/Thumiel_Zaul)\
**Post date:** [November 15, 2023, 11:38am UTC](https://forums.eveonline.com/t/esi-refresh-token-400-bad-request/427381/2 "2023-11-15T11:38:23Z")

</div>

This issue weirdly seems to have resolved itself with no code changes!

---

<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 13, 2024, 11:39am UTC](https://forums.eveonline.com/t/esi-refresh-token-400-bad-request/427381/3 "2024-02-13T11:39:18Z")

</div>

Closed on February 13, 2024, 11:39am UTC

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