Add minimal auth
This commit is contained in:
parent
aea41069fb
commit
2cf66395fe
5
Pages/Login.cshtml
Normal file
5
Pages/Login.cshtml
Normal file
@ -0,0 +1,5 @@
|
||||
@page
|
||||
|
||||
<p>
|
||||
:D (login)
|
||||
</p>
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
14
Program.cs
14
Program.cs
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user