diff options
Diffstat (limited to 'backend/Elements.Backend/Program.cs')
| -rw-r--r-- | backend/Elements.Backend/Program.cs | 53 |
1 files changed, 42 insertions, 11 deletions
diff --git a/backend/Elements.Backend/Program.cs b/backend/Elements.Backend/Program.cs index 15eacee..50e5255 100644 --- a/backend/Elements.Backend/Program.cs +++ b/backend/Elements.Backend/Program.cs @@ -1,23 +1,54 @@ +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;
+});
-builder.Services.AddControllers();
-// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
-builder.Services.AddEndpointsApiExplorer();
-builder.Services.AddSwaggerGen();
-
-var app = builder.Build();
-
-// Configure the HTTP request pipeline.
-if (app.Environment.IsDevelopment())
+if (builder.Environment.IsDevelopment())
{
- app.UseSwagger();
- app.UseSwaggerUI();
+ builder.Services.AddDbContext<ApplicationDbContext>(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();
|
