diff options
| author | ivarlovlie <git@ivarlovlie.no> | 2022-12-21 23:37:23 +0100 |
|---|---|---|
| committer | ivarlovlie <git@ivarlovlie.no> | 2022-12-21 23:37:23 +0100 |
| commit | 82ade3c31fb17b662feec59e9e654ceb66edbb7a (patch) | |
| tree | 26443c41c55d2cd2ae46fdd0d663aca84b779ffe /code/api/Program.cs | |
| parent | e60703aadca7d423c0fbfb189d5ef439fc1df072 (diff) | |
| download | storage-82ade3c31fb17b662feec59e9e654ceb66edbb7a.tar.xz storage-82ade3c31fb17b662feec59e9e654ceb66edbb7a.zip | |
feat: Add initial schema and start login
Diffstat (limited to 'code/api/Program.cs')
| -rw-r--r-- | code/api/Program.cs | 55 |
1 files changed, 43 insertions, 12 deletions
diff --git a/code/api/Program.cs b/code/api/Program.cs index 1b0b1b5..e6281f7 100644 --- a/code/api/Program.cs +++ b/code/api/Program.cs @@ -1,20 +1,51 @@ +global using Microsoft.AspNetCore.Mvc; +global using IOL.Helpers; +global using I2R.Storage.Api.Services.Admin; +global using Microsoft.AspNetCore.Mvc.RazorPages; +global using Microsoft.EntityFrameworkCore; +global using I2R.Storage.Api.Database; +global using I2R.Storage.Api.Utilities; +global using I2R.Storage.Api.Database.Models; +global using I2R.Storage.Api.Resources; +global using I2R.Storage.Api.Enums; +global using Microsoft.Extensions.Localization; +global using I2R.Storage.Api.Statics; +global using Microsoft.AspNetCore.Authorization; +global using System.Security.Claims; +using Microsoft.AspNetCore.Authentication.Cookies; +using Microsoft.AspNetCore.Localization; + var builder = WebApplication.CreateBuilder(args); +builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) + .AddCookie(o => { + o.Cookie.Name = "storage_session"; + o.Cookie.HttpOnly = true; + }); +builder.Services.AddAuthorization(o => { + o.AddPolicy("least_privileged", b => { b.RequireRole("least_privileged"); }); + o.AddPolicy("admin", b => { b.RequireRole("admin"); }); +}); +builder.Services.AddLocalization(); +builder.Services.AddRequestLocalization(o => { o.DefaultRequestCulture = new RequestCulture("en"); }); +builder.Services.AddScoped<UserService>(); +builder.Services.AddDbContext<AppDatabase>(o => { + o.UseNpgsql(builder.Configuration.GetAppDbConnectionString(), b => { + b.UseQuerySplittingBehavior(QuerySplittingBehavior.SplitQuery); + b.EnableRetryOnFailure(3); + }); + o.UseSnakeCaseNamingConvention(); +}); +builder.Services.AddRazorPages().AddRazorRuntimeCompilation(); builder.Services.AddControllers(); -builder.Services.AddEndpointsApiExplorer(); -builder.Services.AddSwaggerGen(); var app = builder.Build(); -if (app.Environment.IsDevelopment()) -{ - app.UseSwagger(); - app.UseSwaggerUI(); -} - - +app.UseStaticFiles(); +app.UseStatusCodePages(); +app.UseRequestLocalization(); app.UseAuthorization(); - +app.UseAuthentication(); +app.MapRazorPages(); app.MapControllers(); - -app.Run(); +app.Run();
\ No newline at end of file |
