Introduced a static AuthExtensions class providing an AuthorizePolicyAsync extension method for IAuthorizationService. This method streamlines policy-based authorization checks by returning a boolean result for a given user and policy name.
26 lines
744 B
C#
26 lines
744 B
C#
using Microsoft.AspNetCore.Authorization;
|
|
using System.Security.Claims;
|
|
|
|
namespace EnvelopeGenerator.API.Extensions;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public static class AuthExtensions
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="authService"></param>
|
|
/// <param name="user"></param>
|
|
/// <param name="policyName"></param>
|
|
/// <returns></returns>
|
|
public static async Task<bool> AuthorizePolicyAsync(this IAuthorizationService authService,
|
|
ClaimsPrincipal user,
|
|
string policyName)
|
|
{
|
|
var result = await authService.AuthorizeAsync(user, policyName);
|
|
return result.Succeeded;
|
|
}
|
|
}
|