2020-07-03 11:47:27 +00:00
|
|
|
|
using ASC.Api.Core.Core;
|
2020-06-23 10:48:36 +00:00
|
|
|
|
using ASC.Api.Core.Middleware;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
|
using Microsoft.AspNetCore.HttpOverrides;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc.Formatters;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2020-07-03 15:57:59 +00:00
|
|
|
|
using Microsoft.AspNetCore.Authentication;
|
|
|
|
|
using ASC.Api.Core.Auth;
|
2020-06-23 10:48:36 +00:00
|
|
|
|
|
2020-07-03 11:47:27 +00:00
|
|
|
|
namespace ASC.Api.Core
|
2020-06-23 10:48:36 +00:00
|
|
|
|
{
|
2020-07-03 15:57:59 +00:00
|
|
|
|
public static class GeneralStartup
|
2020-06-23 10:48:36 +00:00
|
|
|
|
{
|
2020-07-03 15:57:59 +00:00
|
|
|
|
public static void ConfigureServices(IServiceCollection services, bool confirmAddScheme)
|
2020-06-23 10:48:36 +00:00
|
|
|
|
{
|
2020-07-03 15:57:59 +00:00
|
|
|
|
|
2020-06-23 10:48:36 +00:00
|
|
|
|
services.AddHttpContextAccessor();
|
|
|
|
|
|
|
|
|
|
services.AddControllers()
|
2020-07-03 11:47:27 +00:00
|
|
|
|
.AddXmlSerializerFormatters()
|
|
|
|
|
.AddJsonOptions(options =>
|
|
|
|
|
{
|
|
|
|
|
options.JsonSerializerOptions.WriteIndented = false;
|
|
|
|
|
options.JsonSerializerOptions.IgnoreNullValues = true;
|
|
|
|
|
options.JsonSerializerOptions.Converters.Add(new ApiDateTimeConverter());
|
|
|
|
|
});
|
2020-06-23 10:48:36 +00:00
|
|
|
|
|
|
|
|
|
var builder = services.AddMvcCore(config =>
|
|
|
|
|
{
|
|
|
|
|
var policy = new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build();
|
|
|
|
|
config.Filters.Add(new AuthorizeFilter(policy));
|
|
|
|
|
config.Filters.Add(new TypeFilterAttribute(typeof(TenantStatusFilter)));
|
|
|
|
|
config.Filters.Add(new TypeFilterAttribute(typeof(PaymentFilter)));
|
|
|
|
|
config.Filters.Add(new TypeFilterAttribute(typeof(IpSecurityFilter)));
|
|
|
|
|
config.Filters.Add(new TypeFilterAttribute(typeof(ProductSecurityFilter)));
|
|
|
|
|
config.Filters.Add(new CustomResponseFilterAttribute());
|
|
|
|
|
config.Filters.Add(new CustomExceptionFilterAttribute());
|
|
|
|
|
config.Filters.Add(new TypeFilterAttribute(typeof(FormatFilter)));
|
|
|
|
|
|
|
|
|
|
config.OutputFormatters.RemoveType<XmlSerializerOutputFormatter>();
|
|
|
|
|
config.OutputFormatters.Add(new XmlOutputFormatter());
|
|
|
|
|
});
|
2020-07-03 15:57:59 +00:00
|
|
|
|
|
|
|
|
|
if (confirmAddScheme)
|
|
|
|
|
{
|
|
|
|
|
services.AddAuthentication("cookie")
|
|
|
|
|
.AddScheme<AuthenticationSchemeOptions, CookieAuthHandler>("cookie", a => { })
|
|
|
|
|
.AddScheme<AuthenticationSchemeOptions, ConfirmAuthHandler>("confirm", a => { });
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
services.AddAuthentication("cookie")
|
|
|
|
|
.AddScheme<AuthenticationSchemeOptions, CookieAuthHandler>("cookie", a => { });
|
|
|
|
|
}
|
2020-06-23 10:48:36 +00:00
|
|
|
|
}
|
2020-07-03 15:57:59 +00:00
|
|
|
|
public static void Configure(IApplicationBuilder app)
|
2020-06-23 10:48:36 +00:00
|
|
|
|
{
|
|
|
|
|
app.UseForwardedHeaders(new ForwardedHeadersOptions
|
|
|
|
|
{
|
|
|
|
|
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
|
|
|
|
|
});
|
|
|
|
|
app.UseRouting();
|
|
|
|
|
|
|
|
|
|
app.UseAuthentication();
|
|
|
|
|
|
|
|
|
|
app.UseAuthorization();
|
|
|
|
|
|
|
|
|
|
app.UseCultureMiddleware();
|
|
|
|
|
|
|
|
|
|
app.UseDisposeMiddleware();
|
|
|
|
|
|
|
|
|
|
app.UseEndpoints(endpoints =>
|
|
|
|
|
{
|
|
|
|
|
endpoints.MapControllers();
|
|
|
|
|
endpoints.MapCustom();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-03 11:47:27 +00:00
|
|
|
|
}
|