Files
Aleksandr Popov 171b640230 editorconfig added,
modelbuilder fix for local connString
2023-06-26 08:58:42 +02:00

75 lines
2.6 KiB
C#

using System.Reflection;
using Microsoft.IdentityModel.Tokens;
using Microsoft.OpenApi.Models;
using Newtonsoft.Json.Converters;
using TURN.Services.Chess.DBModel;
namespace TURN.Services.Chess
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
ConfigureSwagger(services);
ConfigureAuthorization(services);
_ = services.AddControllers();
_ = services.AddControllers().AddNewtonsoftJson(jsonOptions =>
{
jsonOptions.SerializerSettings.Converters.Add(new StringEnumConverter());
});
_ = services.AddDbContext<ModelBaseContext>();
}
public void Configure(IApplicationBuilder app)
{
_ = app.UseRouting();
_ = app.UseAuthentication();
_ = app.UseAuthorization();
_ = app.UseSwagger();
_ = app.UseSwaggerUI();
_ = app.UseEndpoints(endpoints =>
{
_ = endpoints.MapControllers();
_ = endpoints.MapControllerRoute(
name: "default",
pattern: "{controller}/{action}");
_ = endpoints.MapSwagger();
});
}
private void ConfigureSwagger(IServiceCollection services)
{
_ = services.AddSwaggerGen(options =>
{
options.SwaggerDoc("v1", new OpenApiInfo
{
Title = "TURN.Api.Swagger",
Version = "v1"
});
var xmlFilename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename));
});
_ = services.AddSwaggerGenNewtonsoftSupport();
}
private void ConfigureAuthorization(IServiceCollection services)
{
_ = services.AddAuthentication()
.AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidIssuer = AuthOptions.ISSUER,
ValidateAudience = true,
ValidAudience = AuthOptions.AUDIENCE,
ValidateLifetime = true,
IssuerSigningKey = AuthOptions.GetSymmetricSecurityKey(),
ValidateIssuerSigningKey = true,
};
});
_ = services.AddAuthorization();
}
}
}