Example #1
0
        public async Task <CommandResult> Handle(DisconnectCommand request, CancellationToken cancellationToken)
        {
            var client = new XeroClient(_xeroConfig.Value, _httpClientFactory.CreateClient("xero"));

            var xeroToken = await _tokenRepository.Get();

            if (xeroToken is null)
            {
                return(CommandResult.Fail("No Connection Found"));
            }

            var utcTimeNow = DateTime.UtcNow;

            if (utcTimeNow > xeroToken.ExpiresAtUtc)
            {
                xeroToken = (XeroOAuth2Token)await client.RefreshAccessTokenAsync(xeroToken);

                await _tokenRepository.Create(xeroToken);
            }

            var xeroTenant = xeroToken.Tenants[0];
            await client.DeleteConnectionAsync(xeroToken, xeroTenant);

            await _tokenRepository.Delete();

            return(CommandResult.Success);
        }
Example #2
0
        public async Task <IActionResult> DiconnectAsync(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = "Authorization/Disconnect")] HttpRequest req
            , ILogger log
            )
        {
            var xeroToken = await _tokenStore.GetStoredToken("");

            var xeroTenant = xeroToken.Tenants.First();
            await _client.DeleteConnectionAsync(xeroToken, xeroTenant);

            await _tokenStore.DestroyToken();

            return(new JsonResult(xeroTenant));
        }
Example #3
0
        // GET /Authorization/Disconnect
        public async Task <ActionResult> Disconnect()
        {
            var client = new XeroClient(XeroConfig.Value, httpClientFactory);

            var xeroToken  = TokenUtilities.GetStoredToken();
            var utcTimeNow = DateTime.UtcNow;

            if (utcTimeNow > xeroToken.ExpiresAtUtc)
            {
                xeroToken = (XeroOAuth2Token)await client.RefreshAccessTokenAsync(xeroToken);

                TokenUtilities.StoreToken(xeroToken);
            }

            string accessToken = xeroToken.AccessToken;
            Tenant xeroTenant  = xeroToken.Tenants[0];

            await client.DeleteConnectionAsync(xeroToken, xeroTenant);

            TokenUtilities.DestroyToken();

            return(RedirectToAction("Index", "Home"));
        }