// GET: /Authorization/Callback public async Task <ActionResult> Callback(string code, string state) { var serviceProvider = new ServiceCollection().AddHttpClient().BuildServiceProvider(); var httpClientFactory = serviceProvider.GetService <IHttpClientFactory>(); XeroConfiguration XeroConfig = new XeroConfiguration { ClientId = ConfigurationManager.AppSettings["XeroClientId"], ClientSecret = ConfigurationManager.AppSettings["XeroClientSecret"], CallbackUri = new Uri(ConfigurationManager.AppSettings["XeroCallbackUri"]), Scope = ConfigurationManager.AppSettings["XeroScope"], State = ConfigurationManager.AppSettings["XeroState"] }; var client = new XeroClient(XeroConfig, httpClientFactory); var xeroToken = (XeroOAuth2Token)await client.RequestXeroTokenAsync(code); List <Tenant> tenants = await client.GetConnectionsAsync(xeroToken); Tenant firstTenant = tenants[0]; TokenUtilities.StoreToken(xeroToken); return(RedirectToAction("Index", "OrganisationInfo")); }
// GET /Authorization/Callback public async Task <ActionResult> Callback(string code, string state) { var client = new XeroClient(XeroConfig.Value, httpClientFactory); var xeroToken = (XeroOAuth2Token)await client.RequestXeroTokenAsync(code); List <Tenant> tenants = await client.GetConnectionsAsync(xeroToken); Tenant firstTenant = tenants[0]; TokenUtilities.StoreToken(xeroToken); return(RedirectToAction("Index", "OrganisationInfo")); }
public async Task <IActionResult> CallbackAsync( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "Authorization/Callback")] HttpRequest req , ILogger log ) { var code = req.Query["code"]; var xeroToken = (XeroOAuth2Token)await _client.RequestXeroTokenAsync(code); await _tokenStore.StoreToken(xeroToken); return(new OkResult()); }
public async Task <IXeroToken> GetTokensAsync(string code, string state) { var client = new XeroClient(_xeroConfig, _httpClientFactory); //before getting the access token please check that the state matches _xeroToken = await client.RequestXeroTokenAsync(code); //from here you will need to access your Xero Tenants List <Tenant> tenants = await client.GetConnectionsAsync(_xeroToken); _xeroToken.Tenants = tenants; return(_xeroToken); }