public async Task <IActionResult> CallBack(string code, string session_state) { XeroConfiguration xconfig = new XeroConfiguration(); xconfig.ClientId = "713B16BE2997493E8F3F37AD00400F25"; xconfig.ClientSecret = "GCu6vvrQ6HFgzWKsOAysK2Q78rtQW_jB_V97sKbGvulKuhib"; xconfig.CallbackUri = new Uri("http://localhost:5000/signin-oidc"); //default for standard webapi template xconfig.Scope = "openid profile email files accounting.transactions accounting.contacts offline_access accounting.contacts.read"; var client = new XeroClient(xconfig, _httpClientFactory); //before getting the access token please check that the state matches var token = await client.RequestAccessTokenAsync(code); XeroEmployeeService.Token = token; XeroEmployeeService.Client = client; // //from here you will need to access your Xero Tenants // List<Tenant> tenants = await client.GetConnectionsAsync(token); // // // 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; // } return(Redirect("index.html")); }
// GET /Authorization/Callback public async Task <ActionResult> Callback(string code, string state) { var client = new XeroClient(XeroConfig.Value); var xeroToken = (XeroOAuth2Token)await client.RequestAccessTokenAsync(code); List <Tenant> tenants = await client.GetConnectionsAsync(xeroToken); Tenant firstTenant = tenants[0]; TokenUtilities.StoreToken(xeroToken); return(Redirect("http://localhost:3000/home")); }
public async Task <CommandResult> Handle(CreateAccessTokenCommand request, CancellationToken cancellationToken) { //If Xero Auth flow was cancelled by used if (string.IsNullOrWhiteSpace(request.Code)) { return(CommandResult.Success); } var client = new XeroClient(_xeroConfig.Value, _httpClientFactory.CreateClient("xero")); var xeroToken = (XeroOAuth2Token)await client.RequestAccessTokenAsync(request.Code); await _tokenRepository.Create(xeroToken); return(CommandResult.Success); }