ESI Refresh Token 400 Bad Request

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#.

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

                //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;
                    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 :slight_smile:

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

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