LANCommander.PlaynitePlugin/LANCommander/Program.cs

92 lines
2.7 KiB
C#
Raw Normal View History

2023-01-02 15:44:04 -06:00
using LANCommander.Data;
using LANCommander.Data.Models;
2023-01-04 23:45:11 -06:00
using Microsoft.AspNetCore.Authentication.JwtBearer;
2023-01-02 15:44:04 -06:00
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
2023-01-04 23:45:11 -06:00
using Microsoft.IdentityModel.Tokens;
using System.Text;
2023-01-02 15:44:04 -06:00
var builder = WebApplication.CreateBuilder(args);
2023-01-04 23:45:11 -06:00
ConfigurationManager configuration = builder.Configuration;
2023-01-02 15:44:04 -06:00
// Add services to the container.
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
2023-01-02 18:31:17 -06:00
builder.Services.AddDbContext<LANCommander.Data.DatabaseContext>(b =>
{
b.UseLazyLoadingProxies();
b.UseSqlite(connectionString);
});
2023-01-02 15:44:04 -06:00
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
2023-01-04 23:45:11 -06:00
builder.Services.AddDefaultIdentity<User>((IdentityOptions options) =>
{
options.SignIn.RequireConfirmedAccount = false;
2023-01-02 15:44:04 -06:00
options.Password.RequireNonAlphanumeric = false;
options.SignIn.RequireConfirmedEmail = false;
})
.AddRoles<Role>()
2023-01-04 23:45:11 -06:00
.AddEntityFrameworkStores<LANCommander.Data.DatabaseContext>()
.AddDefaultTokenProviders();
builder.Services.AddAuthentication(options =>
{
/*options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;*/
})
.AddJwtBearer(options =>
{
options.SaveToken = true;
options.RequireHttpsMetadata = false;
options.TokenValidationParameters = new TokenValidationParameters()
{
ValidateIssuer = false,
ValidateAudience = false,
// ValidAudience = configuration["JWT:ValidAudience"],
// ValidIssuer = configuration["JWT:ValidIssuer"],
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(configuration["JWT:Secret"]))
};
});
2023-01-02 15:44:04 -06:00
2023-01-04 20:00:11 -06:00
builder.Services.AddControllersWithViews().AddJsonOptions(x =>
{
x.JsonSerializerOptions.ReferenceHandler = System.Text.Json.Serialization.ReferenceHandler.IgnoreCycles;
});
2023-01-02 15:44:04 -06:00
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseMigrationsEndPoint();
}
else
{
app.UseExceptionHandler("/Home/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.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.MapRazorPages();
if (!Directory.Exists("Upload"))
Directory.CreateDirectory("Upload");
app.Run();