71 lines
2.1 KiB
C#
71 lines
2.1 KiB
C#
|
using Microsoft.AspNetCore.Authentication;
|
||
|
using Microsoft.AspNetCore.Builder;
|
||
|
using Microsoft.AspNetCore.Hosting;
|
||
|
using Microsoft.EntityFrameworkCore;
|
||
|
using Microsoft.Extensions.Configuration;
|
||
|
using Microsoft.Extensions.DependencyInjection;
|
||
|
using Microsoft.Extensions.Hosting;
|
||
|
|
||
|
namespace BlazingPizza.Server
|
||
|
{
|
||
|
public class Startup
|
||
|
{
|
||
|
public Startup(IConfiguration configuration)
|
||
|
{
|
||
|
Configuration = configuration;
|
||
|
}
|
||
|
|
||
|
public IConfiguration Configuration { get; }
|
||
|
|
||
|
public void ConfigureServices(IServiceCollection services)
|
||
|
{
|
||
|
services.AddMvc()
|
||
|
.AddNewtonsoftJson();
|
||
|
|
||
|
services.AddDbContext<PizzaStoreContext>(options =>
|
||
|
options.UseSqlite("Data Source=pizza.db"));
|
||
|
|
||
|
services.AddDefaultIdentity<PizzaStoreUser>(options => options.SignIn.RequireConfirmedAccount = true)
|
||
|
.AddEntityFrameworkStores<PizzaStoreContext>();
|
||
|
|
||
|
services.AddIdentityServer()
|
||
|
.AddApiAuthorization<PizzaStoreUser, PizzaStoreContext>();
|
||
|
|
||
|
services.AddAuthentication()
|
||
|
.AddIdentityServerJwt();
|
||
|
}
|
||
|
|
||
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||
|
{
|
||
|
if (env.IsDevelopment())
|
||
|
{
|
||
|
app.UseDeveloperExceptionPage();
|
||
|
app.UseWebAssemblyDebugging();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
app.UseExceptionHandler("/Error");
|
||
|
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
||
|
// app.UseHsts();
|
||
|
}
|
||
|
|
||
|
// app.UseHttpsRedirection();
|
||
|
app.UseBlazorFrameworkFiles();
|
||
|
app.UseStaticFiles();
|
||
|
|
||
|
app.UseRouting();
|
||
|
|
||
|
app.UseAuthentication();
|
||
|
app.UseIdentityServer();
|
||
|
app.UseAuthorization();
|
||
|
|
||
|
app.UseEndpoints(endpoints =>
|
||
|
{
|
||
|
endpoints.MapControllers();
|
||
|
endpoints.MapRazorPages();
|
||
|
endpoints.MapFallbackToFile("index.html");
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
}
|