Skip to content

Instantly share code, notes, and snippets.

@henzard
Created January 5, 2021 11:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henzard/04a5d882cc0fd770cc3b93c32df4e598 to your computer and use it in GitHub Desktop.
Save henzard/04a5d882cc0fd770cc3b93c32df4e598 to your computer and use it in GitHub Desktop.
public XeroClient GetClient()
{
var xeroConfig = new XeroConfiguration()
{
ClientId = _xeroConfig.Value.XeroConnect.ClientId,
CallbackUri = new Uri(_xeroConfig.Value.XeroConnect.RedirectUri),
Scope =
"openid profile email offline_access files accounting.transactions accounting.contacts accounting.settings",
State = "WinFormsApp"
};
return new XeroClient(xeroConfig);
}
private async Task<string> Refresh()
{
var xeroClient = GetClient();
var token = _xeroTokenStore.Find(p => p.TenantId == _xeroConfig.Value.XeroConnect.TenantId)
.FirstOrDefault();
token = await xeroClient.RefreshAccessTokenAsync(token) as DbXeroToken;
_xeroTokenStore.Upsert(new DbXeroToken(_xeroConfig.Value.XeroConnect.TenantId, token));
return token?.AccessToken;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment