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:
parent
f5c1af1535
commit
0823cb977d
@ -1,16 +1,8 @@
|
|||||||
using Microsoft.AspNetCore.Authentication;
|
namespace WebhookClient.Controllers;
|
||||||
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
|
[Authorize]
|
||||||
|
public class AccountController : Controller
|
||||||
{
|
{
|
||||||
[Authorize]
|
|
||||||
public class AccountController : Controller
|
|
||||||
{
|
|
||||||
public async Task<IActionResult> SignIn(string returnUrl)
|
public async Task<IActionResult> SignIn(string returnUrl)
|
||||||
{
|
{
|
||||||
var user = User as ClaimsPrincipal;
|
var user = User as ClaimsPrincipal;
|
||||||
@ -33,5 +25,4 @@ namespace WebhookClient.Controllers
|
|||||||
return new SignOutResult(OpenIdConnectDefaults.AuthenticationScheme,
|
return new SignOutResult(OpenIdConnectDefaults.AuthenticationScheme,
|
||||||
new AuthenticationProperties { RedirectUri = homeUrl });
|
new AuthenticationProperties { RedirectUri = homeUrl });
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,9 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
namespace WebhookClient.Controllers;
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using Microsoft.Extensions.Options;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using WebhookClient.Models;
|
|
||||||
using WebhookClient.Services;
|
|
||||||
|
|
||||||
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 Settings _settings;
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
@ -49,5 +41,4 @@ namespace WebhookClient.Controllers
|
|||||||
_logger.LogInformation("Received hook is NOT processed - Bad Request returned.");
|
_logger.LogInformation("Received hook is NOT processed - Bad Request returned.");
|
||||||
return BadRequest();
|
return BadRequest();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
27
src/Web/WebhookClient/GlobalUsings.cs
Normal file
27
src/Web/WebhookClient/GlobalUsings.cs
Normal 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;
|
@ -1,7 +1,6 @@
|
|||||||
namespace WebhookClient
|
namespace WebhookClient;
|
||||||
|
|
||||||
|
static class HeaderNames
|
||||||
{
|
{
|
||||||
static class HeaderNames
|
|
||||||
{
|
|
||||||
public const string WebHookCheckHeader = "X-eshop-whtoken";
|
public const string WebHookCheckHeader = "X-eshop-whtoken";
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,8 @@
|
|||||||
using Microsoft.AspNetCore.Authentication;
|
namespace WebhookClient;
|
||||||
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
|
public class HttpClientAuthorizationDelegatingHandler
|
||||||
{
|
|
||||||
public class HttpClientAuthorizationDelegatingHandler
|
|
||||||
: DelegatingHandler
|
: DelegatingHandler
|
||||||
{
|
{
|
||||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||||
|
|
||||||
public HttpClientAuthorizationDelegatingHandler(IHttpContextAccessor httpContextAccessor)
|
public HttpClientAuthorizationDelegatingHandler(IHttpContextAccessor httpContextAccessor)
|
||||||
@ -45,5 +37,4 @@ namespace WebhookClient
|
|||||||
return await _httpContextAccessor.HttpContext
|
return await _httpContextAccessor.HttpContext
|
||||||
.GetTokenAsync(ACCESS_TOKEN);
|
.GetTokenAsync(ACCESS_TOKEN);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,10 @@
|
|||||||
using System;
|
namespace WebhookClient.Models;
|
||||||
|
|
||||||
namespace WebhookClient.Models
|
public class WebHookReceived
|
||||||
{
|
{
|
||||||
public class WebHookReceived
|
|
||||||
{
|
|
||||||
public DateTime When { get; set; }
|
public DateTime When { get; set; }
|
||||||
|
|
||||||
public string Data { get; set; }
|
public string Data { get; set; }
|
||||||
|
|
||||||
public string Token { get; set; }
|
public string Token { get; set; }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,10 @@
|
|||||||
using System;
|
namespace WebhookClient.Models;
|
||||||
|
|
||||||
namespace WebhookClient.Models
|
public class WebhookData
|
||||||
{
|
{
|
||||||
public class WebhookData
|
|
||||||
{
|
|
||||||
public DateTime When { get; set; }
|
public DateTime When { get; set; }
|
||||||
|
|
||||||
public string Payload { get; set; }
|
public string Payload { get; set; }
|
||||||
|
|
||||||
public string Type { get; set; }
|
public string Type { get; set; }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
using System;
|
namespace WebhookClient.Models;
|
||||||
|
|
||||||
namespace WebhookClient.Models
|
public class WebhookResponse
|
||||||
{
|
{
|
||||||
public class WebhookResponse
|
|
||||||
{
|
|
||||||
public DateTime Date { get; set; }
|
public DateTime Date { get; set; }
|
||||||
public string DestUrl { get; set; }
|
public string DestUrl { get; set; }
|
||||||
public string Token { get; set; }
|
public string Token { get; set; }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
namespace WebhookClient.Models
|
namespace WebhookClient.Models;
|
||||||
|
|
||||||
|
public class WebhookSubscriptionRequest
|
||||||
{
|
{
|
||||||
public class WebhookSubscriptionRequest
|
|
||||||
{
|
|
||||||
public string Url { get; set; }
|
public string Url { get; set; }
|
||||||
public string Token { get; set; }
|
public string Token { get; set; }
|
||||||
public string Event { get; set; }
|
public string Event { get; set; }
|
||||||
public string GrantUrl { get; set; }
|
public string GrantUrl { get; set; }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,4 @@
|
|||||||
using Microsoft.AspNetCore;
|
CreateWebHostBuilder(args).Build().Run();
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using WebhookClient;
|
|
||||||
|
|
||||||
CreateWebHostBuilder(args).Build().Run();
|
|
||||||
|
|
||||||
|
|
||||||
IWebHostBuilder CreateWebHostBuilder(string[] args) =>
|
IWebHostBuilder CreateWebHostBuilder(string[] args) =>
|
||||||
|
@ -1,12 +1,7 @@
|
|||||||
using System.Collections.Generic;
|
namespace WebhookClient.Services;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using WebhookClient.Models;
|
|
||||||
|
|
||||||
namespace WebhookClient.Services
|
public interface IHooksRepository
|
||||||
{
|
{
|
||||||
public interface IHooksRepository
|
|
||||||
{
|
|
||||||
Task<IEnumerable<WebHookReceived>> GetAll();
|
Task<IEnumerable<WebHookReceived>> GetAll();
|
||||||
Task AddNew(WebHookReceived hook);
|
Task AddNew(WebHookReceived hook);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,6 @@
|
|||||||
using System.Collections.Generic;
|
namespace WebhookClient.Services;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using WebhookClient.Models;
|
|
||||||
|
|
||||||
namespace WebhookClient.Services
|
public interface IWebhooksClient
|
||||||
{
|
{
|
||||||
public interface IWebhooksClient
|
|
||||||
{
|
|
||||||
Task<IEnumerable<WebhookResponse>> LoadWebhooks();
|
Task<IEnumerable<WebhookResponse>> LoadWebhooks();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,7 @@
|
|||||||
using System.Collections.Generic;
|
namespace WebhookClient.Services;
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using WebhookClient.Models;
|
|
||||||
|
|
||||||
namespace WebhookClient.Services
|
public class InMemoryHooksRepository : IHooksRepository
|
||||||
{
|
{
|
||||||
public class InMemoryHooksRepository : IHooksRepository
|
|
||||||
{
|
|
||||||
private readonly List<WebHookReceived> _data;
|
private readonly List<WebHookReceived> _data;
|
||||||
|
|
||||||
public InMemoryHooksRepository() => _data = new List<WebHookReceived>();
|
public InMemoryHooksRepository() => _data = new List<WebHookReceived>();
|
||||||
@ -21,5 +16,4 @@ namespace WebhookClient.Services
|
|||||||
{
|
{
|
||||||
return Task.FromResult(_data.AsEnumerable());
|
return Task.FromResult(_data.AsEnumerable());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,7 @@
|
|||||||
using Microsoft.Extensions.Options;
|
namespace WebhookClient.Services;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Net.Http;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using WebhookClient.Models;
|
|
||||||
using System.Text.Json;
|
|
||||||
|
|
||||||
namespace WebhookClient.Services
|
public class WebhooksClient : IWebhooksClient
|
||||||
{
|
{
|
||||||
public class WebhooksClient : IWebhooksClient
|
|
||||||
{
|
|
||||||
|
|
||||||
private readonly IHttpClientFactory _httpClientFactory;
|
private readonly IHttpClientFactory _httpClientFactory;
|
||||||
private readonly Settings _settings;
|
private readonly Settings _settings;
|
||||||
@ -28,5 +21,4 @@ namespace WebhookClient.Services
|
|||||||
});
|
});
|
||||||
return subscriptions;
|
return subscriptions;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
namespace WebhookClient
|
namespace WebhookClient;
|
||||||
|
|
||||||
|
public class Settings
|
||||||
{
|
{
|
||||||
public class Settings
|
|
||||||
{
|
|
||||||
public string Token { get; set; }
|
public string Token { get; set; }
|
||||||
public string IdentityUrl { get; set; }
|
public string IdentityUrl { get; set; }
|
||||||
public string CallBackUrl { get; set; }
|
public string CallBackUrl { get; set; }
|
||||||
@ -10,5 +10,4 @@
|
|||||||
|
|
||||||
public bool ValidateToken { get; set; }
|
public bool ValidateToken { get; set; }
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,22 +1,7 @@
|
|||||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
namespace WebhookClient;
|
||||||
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
|
public class Startup
|
||||||
{
|
{
|
||||||
public class Startup
|
|
||||||
{
|
|
||||||
public Startup(IConfiguration configuration)
|
public Startup(IConfiguration configuration)
|
||||||
{
|
{
|
||||||
Configuration = configuration;
|
Configuration = configuration;
|
||||||
@ -107,10 +92,10 @@ namespace WebhookClient
|
|||||||
endpoints.MapRazorPages();
|
endpoints.MapRazorPages();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static class ServiceExtensions
|
static class ServiceExtensions
|
||||||
{
|
{
|
||||||
public static IServiceCollection AddConfiguration(this IServiceCollection services, IConfiguration configuration)
|
public static IServiceCollection AddConfiguration(this IServiceCollection services, IConfiguration configuration)
|
||||||
{
|
{
|
||||||
services.AddOptions();
|
services.AddOptions();
|
||||||
@ -161,5 +146,4 @@ namespace WebhookClient
|
|||||||
|
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -13,9 +13,9 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" />
|
<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.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>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user