using System.Text.Json; using Elements.Data; using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Authentication.Google; using Microsoft.EntityFrameworkCore; var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddRouting(options => options.LowercaseUrls = true); builder.Services.AddControllers().AddJsonOptions(options => { options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase; }); if (builder.Environment.IsDevelopment()) { builder.Services.AddDbContext(options => { options.UseSqlite("Data Source=elements.db"); }); } builder.Services .AddAuthentication(options => { options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; }) .AddCookie(options => { options.Events = new() { OnRedirectToLogin = (ctx) => { ctx.Response.StatusCode = 401; return Task.CompletedTask; }, OnRedirectToAccessDenied = (ctx) => { ctx.Response.StatusCode = 401; return Task.CompletedTask; } }; }); var app = builder.Build(); app.UseHttpsRedirection(); app.UseAuthentication(); app.UseAuthorization(); app.MapControllers(); app.Run();