Most működik alapból
This commit is contained in:
@@ -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<IndexModel> _logger;
|
||||
|
||||
@@ -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<IndexModel> _logger;
|
||||
|
||||
@@ -26,6 +26,9 @@ builder.Host.UseSerilog();
|
||||
// Add services to the container.
|
||||
builder.Services.AddRazorPages();
|
||||
builder.Services.AddSingleton<JwtService>();
|
||||
|
||||
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) &&
|
||||
|
||||
Reference in New Issue
Block a user