Updates webhook client project to .NET 6.0 (#1777)

* Included globalusing file for webhookclient

* Included file scope namespaces for Webhookclient

* Updated packages in WebHookClient project
This commit is contained in:
Sumit Ghosh 2021-10-25 18:35:03 +05:30 committed by GitHub
parent f5c1af1535
commit 0823cb977d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 308 additions and 364 deletions

View File

@ -1,16 +1,8 @@
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Security.Claims;
using System.Threading.Tasks;
namespace WebhookClient.Controllers;
namespace WebhookClient.Controllers
[Authorize]
public class AccountController : Controller
{
[Authorize]
public class AccountController : Controller
{
public async Task<IActionResult> SignIn(string returnUrl)
{
var user = User as ClaimsPrincipal;
@ -33,5 +25,4 @@ namespace WebhookClient.Controllers
return new SignOutResult(OpenIdConnectDefaults.AuthenticationScheme,
new AuthenticationProperties { RedirectUri = homeUrl });
}
}
}

View File

@ -1,17 +1,9 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System.Linq;
using System.Threading.Tasks;
using WebhookClient.Models;
using WebhookClient.Services;
namespace WebhookClient.Controllers;
namespace WebhookClient.Controllers
[ApiController]
[Route("webhook-received")]
public class WebhooksReceivedController : Controller
{
[ApiController]
[Route("webhook-received")]
public class WebhooksReceivedController : Controller
{
private readonly Settings _settings;
private readonly ILogger _logger;
@ -49,5 +41,4 @@ namespace WebhookClient.Controllers
_logger.LogInformation("Received hook is NOT processed - Bad Request returned.");
return BadRequest();
}
}
}

View File

@ -0,0 +1,27 @@
global using Microsoft.AspNetCore.Authentication;
global using Microsoft.AspNetCore.Authentication.Cookies;
global using Microsoft.AspNetCore.Authentication.OpenIdConnect;
global using Microsoft.AspNetCore.Authorization;
global using Microsoft.AspNetCore.Mvc;
global using System.Security.Claims;
global using System.Threading.Tasks;
global using Microsoft.Extensions.Logging;
global using Microsoft.Extensions.Options;
global using System.Linq;
global using WebhookClient.Models;
global using WebhookClient.Services;
global using System;
global using System.Collections.Generic;
global using System.Net.Http;
global using System.Text.Json;
global using Microsoft.AspNetCore.Http;
global using System.Net.Http.Headers;
global using System.Threading;
global using Microsoft.AspNetCore;
global using Microsoft.AspNetCore.Hosting;
global using WebhookClient;
global using Microsoft.AspNetCore.Builder;
global using Microsoft.Extensions.Configuration;
global using Microsoft.Extensions.DependencyInjection;
global using Microsoft.Extensions.Hosting;
global using System.Net;

View File

@ -1,7 +1,6 @@
namespace WebhookClient
namespace WebhookClient;
static class HeaderNames
{
static class HeaderNames
{
public const string WebHookCheckHeader = "X-eshop-whtoken";
}
}

View File

@ -1,16 +1,8 @@
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Http;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;
namespace WebhookClient;
namespace WebhookClient
{
public class HttpClientAuthorizationDelegatingHandler
public class HttpClientAuthorizationDelegatingHandler
: DelegatingHandler
{
{
private readonly IHttpContextAccessor _httpContextAccessor;
public HttpClientAuthorizationDelegatingHandler(IHttpContextAccessor httpContextAccessor)
@ -45,5 +37,4 @@ namespace WebhookClient
return await _httpContextAccessor.HttpContext
.GetTokenAsync(ACCESS_TOKEN);
}
}
}

View File

@ -1,13 +1,10 @@
using System;
namespace WebhookClient.Models;
namespace WebhookClient.Models
public class WebHookReceived
{
public class WebHookReceived
{
public DateTime When { get; set; }
public string Data { get; set; }
public string Token { get; set; }
}
}

View File

@ -1,13 +1,10 @@
using System;
namespace WebhookClient.Models;
namespace WebhookClient.Models
public class WebhookData
{
public class WebhookData
{
public DateTime When { get; set; }
public string Payload { get; set; }
public string Type { get; set; }
}
}

View File

@ -1,11 +1,8 @@
using System;
namespace WebhookClient.Models;
namespace WebhookClient.Models
public class WebhookResponse
{
public class WebhookResponse
{
public DateTime Date { get; set; }
public string DestUrl { get; set; }
public string Token { get; set; }
}
}

View File

@ -1,10 +1,9 @@
namespace WebhookClient.Models
namespace WebhookClient.Models;
public class WebhookSubscriptionRequest
{
public class WebhookSubscriptionRequest
{
public string Url { get; set; }
public string Token { get; set; }
public string Event { get; set; }
public string GrantUrl { get; set; }
}
}

View File

@ -1,8 +1,4 @@
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using WebhookClient;
CreateWebHostBuilder(args).Build().Run();
CreateWebHostBuilder(args).Build().Run();
IWebHostBuilder CreateWebHostBuilder(string[] args) =>

View File

@ -1,12 +1,7 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using WebhookClient.Models;
namespace WebhookClient.Services;
namespace WebhookClient.Services
public interface IHooksRepository
{
public interface IHooksRepository
{
Task<IEnumerable<WebHookReceived>> GetAll();
Task AddNew(WebHookReceived hook);
}
}

View File

@ -1,11 +1,6 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using WebhookClient.Models;
namespace WebhookClient.Services;
namespace WebhookClient.Services
public interface IWebhooksClient
{
public interface IWebhooksClient
{
Task<IEnumerable<WebhookResponse>> LoadWebhooks();
}
}

View File

@ -1,12 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WebhookClient.Models;
namespace WebhookClient.Services;
namespace WebhookClient.Services
public class InMemoryHooksRepository : IHooksRepository
{
public class InMemoryHooksRepository : IHooksRepository
{
private readonly List<WebHookReceived> _data;
public InMemoryHooksRepository() => _data = new List<WebHookReceived>();
@ -21,5 +16,4 @@ namespace WebhookClient.Services
{
return Task.FromResult(_data.AsEnumerable());
}
}
}

View File

@ -1,14 +1,7 @@
using Microsoft.Extensions.Options;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using WebhookClient.Models;
using System.Text.Json;
namespace WebhookClient.Services;
namespace WebhookClient.Services
public class WebhooksClient : IWebhooksClient
{
public class WebhooksClient : IWebhooksClient
{
private readonly IHttpClientFactory _httpClientFactory;
private readonly Settings _settings;
@ -28,5 +21,4 @@ namespace WebhookClient.Services
});
return subscriptions;
}
}
}

View File

@ -1,7 +1,7 @@
namespace WebhookClient
namespace WebhookClient;
public class Settings
{
public class Settings
{
public string Token { get; set; }
public string IdentityUrl { get; set; }
public string CallBackUrl { get; set; }
@ -10,5 +10,4 @@
public bool ValidateToken { get; set; }
}
}

View File

@ -1,22 +1,7 @@
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Linq;
using System.Net;
using System.Threading;
using WebhookClient.Services;
namespace WebhookClient;
namespace WebhookClient
public class Startup
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
@ -107,10 +92,10 @@ namespace WebhookClient
endpoints.MapRazorPages();
});
}
}
}
static class ServiceExtensions
{
static class ServiceExtensions
{
public static IServiceCollection AddConfiguration(this IServiceCollection services, IConfiguration configuration)
{
services.AddOptions();
@ -161,5 +146,4 @@ namespace WebhookClient
return services;
}
}
}

View File

@ -13,9 +13,9 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="5.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="6.0.0-preview.7.21378.6" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.8" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.0-preview.7.21413.1" />
</ItemGroup>
</Project>