Add project files.

This commit is contained in:
Sergio Matias Urquin
2025-04-29 18:57:20 -06:00
parent 62e9799537
commit d5925a6476
44 changed files with 2716 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
using Microsoft.AspNetCore.Authorization;
namespace Core.Cerberos.Adapters.Handlers.Adapters
{
public class PermissionsAuthorizationAdapter : IAuthorizationRequirement
{
public PermissionsAuthorizationAdapter(string[] permission)
{
Permission = permission;
}
public string[] Permission { get; set; }
}
}

View File

@@ -0,0 +1,29 @@
// ***********************************************************************
// <copyright file="AuthenticatedHttpClientHandler.cs">
// Heath
// </copyright>
// ***********************************************************************
using Core.Cerberos.Adapters.Contracts;
namespace Core.Cerberos.Adapters.Handlers
{
/// <summary>
/// Class to inject the token in all requests.
/// </summary>
public class AuthenticatedHttpClientHandler(ITokenProvider tokenProvider) : DelegatingHandler
{
private readonly ITokenProvider _tokenProvider = tokenProvider;
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
var token = _tokenProvider.GetToken();
if (!string.IsNullOrEmpty(token))
{
request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
}
return await base.SendAsync(request, cancellationToken);
}
}
}

View File

@@ -0,0 +1,18 @@
using Core.Cerberos.Adapters.Handlers.Adapters;
using Microsoft.AspNetCore.Authorization;
namespace Core.Cerberos.Adapters.Handlers
{
public class PermissionsAuthorizationHandler : AuthorizationHandler<PermissionsAuthorizationAdapter>
{
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, PermissionsAuthorizationAdapter requirement)
{
if (context.User.Claims.Any(x => x.Type == "LSARoleId" && requirement.Permission.Contains(x.Value)))
{
context.Succeed(requirement);
}
return Task.CompletedTask;
}
}
}