Torma Kristóf
8347b10401
All checks were successful
continuous-integration/drone/push Build is passing
123 lines
4.5 KiB
C#
123 lines
4.5 KiB
C#
using HanyadikHetVan.Data;
|
|
using HanyadikHetVan.Services;
|
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.OpenApi.Models;
|
|
using System.Reflection;
|
|
|
|
namespace HanyadikHetVan
|
|
{
|
|
public class Startup
|
|
{
|
|
public Startup(IConfiguration configuration)
|
|
{
|
|
Configuration = configuration;
|
|
}
|
|
|
|
public IConfiguration Configuration { get; }
|
|
|
|
public void ConfigureServices(IServiceCollection services)
|
|
{
|
|
services.AddDbContext<ApplicationDbContext>(options =>
|
|
options.UseSqlServer(
|
|
Configuration.GetConnectionString("DefaultConnection")));
|
|
services.AddAutoMapper(Assembly.GetExecutingAssembly());
|
|
services.AddTransient<WeeklyTimeSpanService>();
|
|
services.AddTransient<PauseService>();
|
|
services.AddTransient<PurseService>();
|
|
services.AddTransient<HanyadikHetVanEntityService>();
|
|
services.AddTransient<HanyadikHetVanJsonService>();
|
|
services.AddTransient<HanyadikHetVanService>();
|
|
services.AddDatabaseDeveloperPageExceptionFilter();
|
|
services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
|
|
.AddEntityFrameworkStores<ApplicationDbContext>();
|
|
|
|
services.AddAuthentication(config =>
|
|
{
|
|
config.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
|
|
})
|
|
.AddJwtBearer(config =>
|
|
{
|
|
config.Authority = "https://localhost:5001";
|
|
config.Audience = "api";
|
|
config.RequireHttpsMetadata = false;
|
|
});
|
|
|
|
services.AddAuthorization(config =>
|
|
{
|
|
config.AddPolicy("default", config => config.RequireAuthenticatedUser().AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme));
|
|
config.DefaultPolicy = config.GetPolicy("default");
|
|
});
|
|
|
|
services.AddIdentityServer()
|
|
.AddDeveloperSigningCredential()
|
|
.AddInMemoryPersistedGrants()
|
|
.AddInMemoryIdentityResources(Configuration.GetSection("IdentityServer:IdentityResources"))
|
|
.AddInMemoryApiResources(Configuration.GetSection("IdentityServer:ApiResources"))
|
|
.AddInMemoryApiScopes(Configuration.GetSection("IdentityServer:ApiScopes"))
|
|
.AddInMemoryClients(Configuration.GetSection("IdentityServer:Clients"))
|
|
.AddAspNetIdentity<IdentityUser>();
|
|
|
|
services.AddRazorPages();
|
|
|
|
services.AddControllers();
|
|
|
|
services.AddApiVersioning(options =>
|
|
{
|
|
options.ReportApiVersions = true;
|
|
});
|
|
|
|
services.AddVersionedApiExplorer(options =>
|
|
{
|
|
options.GroupNameFormat = "'v'VVV";
|
|
options.SubstituteApiVersionInUrl = true;
|
|
});
|
|
|
|
services.AddSwaggerGen(c =>
|
|
{
|
|
c.SwaggerDoc("v1", new OpenApiInfo { Title = "Hanyadik Het Van API", Version = "v1" });
|
|
c.SwaggerDoc("v2", new OpenApiInfo { Title = "Hanyadik Het Van API", Version = "v2" });
|
|
});
|
|
}
|
|
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
|
{
|
|
if (env.IsDevelopment())
|
|
{
|
|
app.UseDeveloperExceptionPage();
|
|
app.UseMigrationsEndPoint();
|
|
app.UseSwagger();
|
|
app.UseSwaggerUI(c =>
|
|
{
|
|
c.SwaggerEndpoint("v1/swagger.json", "Original API");
|
|
c.SwaggerEndpoint("v2/swagger.json", "Homework API");
|
|
});
|
|
}
|
|
else
|
|
{
|
|
app.UseExceptionHandler("/Error");
|
|
}
|
|
|
|
app.UseStaticFiles();
|
|
app.UseIdentityServer();
|
|
|
|
app.UseRouting();
|
|
|
|
app.UseAuthentication();
|
|
app.UseAuthorization();
|
|
|
|
app.UseEndpoints(endpoints =>
|
|
{
|
|
endpoints.MapRazorPages();
|
|
endpoints.MapControllers();
|
|
});
|
|
}
|
|
}
|
|
}
|