2021-05-03 01:30:06 +02:00
|
|
|
using HanyadikHetVan.Data;
|
2021-05-03 15:56:38 +02:00
|
|
|
using HanyadikHetVan.Services;
|
2021-05-03 01:30:06 +02:00
|
|
|
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;
|
|
|
|
|
|
|
|
namespace HanyadikHetVan
|
|
|
|
{
|
|
|
|
public class Startup
|
|
|
|
{
|
|
|
|
public Startup(IConfiguration configuration)
|
|
|
|
{
|
|
|
|
Configuration = configuration;
|
|
|
|
}
|
|
|
|
|
|
|
|
public IConfiguration Configuration { get; }
|
|
|
|
|
|
|
|
// This method gets called by the runtime. Use this method to add services to the container.
|
|
|
|
public void ConfigureServices(IServiceCollection services)
|
|
|
|
{
|
|
|
|
services.AddDbContext<ApplicationDbContext>(options =>
|
|
|
|
options.UseSqlServer(
|
|
|
|
Configuration.GetConnectionString("DefaultConnection")));
|
2021-05-03 15:56:38 +02:00
|
|
|
services.AddTransient<HanyadikHetVanJsonService>();
|
|
|
|
services.AddTransient<HanyadikHetVanService>();
|
2021-05-03 01:30:06 +02:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
|
|
|
{
|
|
|
|
if (env.IsDevelopment())
|
|
|
|
{
|
|
|
|
app.UseDeveloperExceptionPage();
|
|
|
|
app.UseMigrationsEndPoint();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
app.UseExceptionHandler("/Error");
|
|
|
|
}
|
|
|
|
|
|
|
|
app.UseStaticFiles();
|
|
|
|
app.UseIdentityServer();
|
|
|
|
|
|
|
|
app.UseRouting();
|
|
|
|
|
|
|
|
app.UseAuthentication();
|
|
|
|
app.UseAuthorization();
|
|
|
|
|
|
|
|
app.UseEndpoints(endpoints =>
|
|
|
|
{
|
|
|
|
endpoints.MapRazorPages();
|
|
|
|
endpoints.MapControllers();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|