diff --git a/src/WorkFlowCheck.Web/Pages/BaseStock/CheckPoints/CheckPointEditPage.cshtml.cs b/src/WorkFlowCheck.Web/Pages/BaseStock/CheckPoints/CheckPointEditPage.cshtml.cs index f3784e3..dc7206a 100644 --- a/src/WorkFlowCheck.Web/Pages/BaseStock/CheckPoints/CheckPointEditPage.cshtml.cs +++ b/src/WorkFlowCheck.Web/Pages/BaseStock/CheckPoints/CheckPointEditPage.cshtml.cs @@ -1,3 +1,4 @@ +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using WorkFlowCheck.Common.DTO; @@ -5,6 +6,7 @@ using WorkFlowCheck.Web.Services.Interfaces; namespace WorkFlowCheck.Web.Pages.BaseStock.CheckPoints { + [Authorize] public class CheckPointEditPageModel : PageModel { private readonly ILogger _logger; diff --git a/src/WorkFlowCheck.Web/Pages/Index.cshtml.cs b/src/WorkFlowCheck.Web/Pages/Index.cshtml.cs index 5d03c67..11c1aa9 100644 --- a/src/WorkFlowCheck.Web/Pages/Index.cshtml.cs +++ b/src/WorkFlowCheck.Web/Pages/Index.cshtml.cs @@ -1,8 +1,10 @@ +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; namespace WorkFlowCheck.Web.Pages { + //[Authorize] public class IndexModel : PageModel { private readonly ILogger _logger; diff --git a/src/WorkFlowCheck.Web/Program.cs b/src/WorkFlowCheck.Web/Program.cs index 4869e3b..1f5e4d4 100644 --- a/src/WorkFlowCheck.Web/Program.cs +++ b/src/WorkFlowCheck.Web/Program.cs @@ -26,6 +26,9 @@ builder.Host.UseSerilog(); // Add services to the container. builder.Services.AddRazorPages(); builder.Services.AddSingleton(); + +var jwtSettings = builder.Configuration.GetSection("Jwt"); + builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { @@ -37,9 +40,9 @@ builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, - ValidIssuer = "https://auth.example.com", - ValidAudience = "https://mywebapp.com", - IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("super_secret_key")) + ValidIssuer = jwtSettings["Issuer"], + ValidAudience = jwtSettings["Audience"], + IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtSettings["SecretKey"])) }; }); @@ -62,21 +65,6 @@ app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); -app.MapPost("/login", async ([FromBody] UserDTO userDTO, JwtService jwtService, HttpContext httpContext) => -{ - var token = await jwtService.AuthenticateUserAsync(userDTO); - if (token is null) return Results.Unauthorized(); - - httpContext.Response.Cookies.Append("AuthToken", token, new CookieOptions - { - HttpOnly = true, - Secure = true, - SameSite = SameSiteMode.Strict - }); - return Results.Ok(new { Token = token }); -}); - -app.MapGet("/secure-data", [Authorize] () => "This is protected data"); app.Use(async (context, next) => { if (string.IsNullOrEmpty(context.User?.Identity?.Name) &&