Add minimal auth

master
Araozu 2024-08-23 20:44:57 -05:00
parent aea41069fb
commit 2cf66395fe
3 changed files with 26 additions and 1 deletions

5
Pages/Login.cshtml Normal file
View File

@ -0,0 +1,5 @@
@page
<p>
:D (login)
</p>

View File

@ -5,9 +5,15 @@ namespace JergueroCS.Pages
{
public class NewDefinitionModel : PageModel
{
public void OnGet()
public IActionResult OnGet()
{
if (User.Identity?.IsAuthenticated != true)
{
return RedirectToPage("/Login");
}
System.Console.WriteLine(":D");
return Page();
}
}
}

View File

@ -1,7 +1,16 @@
using Microsoft.AspNetCore.Authentication.Cookies;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorPages();
builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(options =>
{
options.ExpireTimeSpan = TimeSpan.FromMinutes(20);
options.SlidingExpiration = true;
options.AccessDeniedPath = "/Forbidden/";
});
var app = builder.Build();
@ -18,6 +27,11 @@ app.UseStaticFiles();
app.UseRouting();
app.UseCookiePolicy(new CookiePolicyOptions
{
MinimumSameSitePolicy = SameSiteMode.Strict,
});
app.UseAuthentication();
app.UseAuthorization();
app.MapRazorPages();