XeroAPI / Xero-NetStandard

A wrapper of the Xero API in the .NetStandard 2.0 framework. Supports Accounting, Payroll AU/US, and Files
MIT License
118 stars 119 forks source link

An error occurred refreshing the Xero access token. Reason: Parameter is required Parameter name: refresh_token #487

Open marcelmgm opened 9 months ago

marcelmgm commented 9 months ago

SDK 2.2.9

Hi, For unknow reason im starting to get this error now: "An error occurred refreshing the Xero access token. Reason: Parameter is required Parameter name: refresh_token"

Anyone else?

Code im using:

public XeroToken GetToken()
{
  ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;

  var xeroOAuth2Token = this.TokenStore.GetToken();

        if (DateTime.UtcNow > xeroOAuth2Token.ExpiresAtUtc)
        {
            var client = new XeroClient(new XeroConfiguration
    {
      AppName = Settings.AppName,
      ClientId = Settings.ClientId,
      ClientSecret = Settings.ClientSecret,
      Scope = Settings.Scopes
    });

    try
    {
              xeroOAuth2Token = (XeroOAuth2Token)client.RefreshAccessTokenAsync(xeroOAuth2Token).Result;
    }
    catch (Exception ex)
            {
      throw new Exception($"An error occurred refreshing the Xero access token. Reason: {(ex.InnerException == null ? ex.Message : ex.InnerException.Message)}");
            }

    this.TokenStore.StoreToken(xeroOAuth2Token);
        }

  return new XeroToken
  {
    AccessToken = xeroOAuth2Token.AccessToken,
    TenantId = Convert.ToString(xeroOAuth2Token.Tenants[0].TenantId)
  };
}
github-actions[bot] commented 9 months ago

PETOSS-353

github-actions[bot] commented 9 months ago

Thanks for raising an issue, a ticket has been created to track your request

marcelmgm commented 8 months ago

I fixed by refreshing token manually using xoauth