Hello Support,
I am trying to access Xero APIs in plugin, Could you please help/guide me how to get the access token in a non-web application using OAuth2.0 authentication approach.
I am trying to get an access token, to get access token we need a code,I am not sure how to get the code or initialize it as I haven't found any details to get the code, the below is the url I am following
github.com/.../oauth2
XeroConfiguration xconfig = new XeroConfiguration();
xconfig.ClientId = "yourClientId";
xconfig.ClientSecret = "yourClientSecret";
xconfig.CallbackUri = new Uri("https://localhost:5001") //default for standard webapi template
xconfig.Scope = "openid profile email files accounting.transactions accounting.contacts offline_access";
var client = new XeroClient(xconfig);
//before getting the access token please check that the state matches
//********************************
await client.RequestAccessTokenAsync(code, "yourState");
//from here you will need to access your Xero Tenants
List<Tenant> tenants = await client.GetConnections();
// you will now have the tenant id and access token
foreach (Tenant tenant in tenants)
{
// do something with your tenant and access token
//client.AccessToken;
//tenant.TenantId;
}
Many thanks in advance
Hemant