commit
1b45afc4e4
|
@ -1,6 +1,5 @@
|
|||
using AuthRequirementsData.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace AuthRequirementsData.Controllers;
|
||||
|
||||
|
@ -10,6 +9,6 @@ public class GreetingsController : Controller
|
|||
{
|
||||
[MinimumAgeAuthorize(16)]
|
||||
[HttpGet("hello")]
|
||||
public string Hello(ClaimsPrincipal user) =>
|
||||
$"Hello {(user.Identity?.Name ?? "world")}!";
|
||||
public string Hello() => $"Hello {(HttpContext.User.Identity?.Name ?? "world")}!";
|
||||
|
||||
}
|
||||
|
|
|
@ -5,11 +5,11 @@ var builder = WebApplication.CreateBuilder();
|
|||
|
||||
builder.Services.AddAuthentication().AddJwtBearer();
|
||||
builder.Services.AddAuthorization();
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddSingleton<IAuthorizationHandler, MinimumAgeAuthorizationHandler>();
|
||||
builder.Services.AddControllers();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
app.Run();
|
||||
|
|
Loading…
Reference in New Issue