Relax and rename auth policies for sender/receiver roles
Replaced SenderOrReceiverFullyAuth and ReceiverFullyAuth policies with more general SenderOrReceiver and Receiver policies. Updated policy definitions in AuthPolicy.cs to use nameof for clarity. Adjusted AddAuthorizationBuilder configuration and [Authorize] attributes in controllers to use the new, less restrictive policies, simplifying authorization logic.
This commit is contained in:
@@ -34,7 +34,7 @@ public partial class AuthController(IOptions<AuthTokenKeys> authTokenKeyOptions)
|
|||||||
/// <response code="401">Wenn es kein zugelassenes Cookie gibt, wird „nicht zugelassen“ zurückgegeben.</response>
|
/// <response code="401">Wenn es kein zugelassenes Cookie gibt, wird „nicht zugelassen“ zurückgegeben.</response>
|
||||||
[ProducesResponseType(typeof(string), StatusCodes.Status200OK, "text/javascript")]
|
[ProducesResponseType(typeof(string), StatusCodes.Status200OK, "text/javascript")]
|
||||||
[ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)]
|
[ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)]
|
||||||
[Authorize(Policy = AuthPolicy.SenderOrReceiverFullyAuth)]
|
[Authorize(Policy = AuthPolicy.SenderOrReceiver)]
|
||||||
[HttpPost("logout")]
|
[HttpPost("logout")]
|
||||||
public async Task<IActionResult> Logout()
|
public async Task<IActionResult> Logout()
|
||||||
{
|
{
|
||||||
@@ -56,7 +56,7 @@ public partial class AuthController(IOptions<AuthTokenKeys> authTokenKeyOptions)
|
|||||||
[ProducesResponseType(typeof(void), StatusCodes.Status200OK)]
|
[ProducesResponseType(typeof(void), StatusCodes.Status200OK)]
|
||||||
[ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)]
|
[ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)]
|
||||||
[HttpGet("check")]
|
[HttpGet("check")]
|
||||||
[Authorize(Policy = AuthPolicy.SenderOrReceiverFullyAuth)]
|
[Authorize(Policy = AuthPolicy.SenderOrReceiver)]
|
||||||
public IActionResult Check([FromQuery] string role) => User.IsInRole(role) ? Ok() : Unauthorized();
|
public IActionResult Check([FromQuery] string role) => User.IsInRole(role) ? Ok() : Unauthorized();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ public class TfaRegistrationController : ControllerBase
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Logs out the envelope receiver from cookie authentication.
|
/// Logs out the envelope receiver from cookie authentication.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Authorize(Policy = AuthPolicy.ReceiverFullyAuth)]
|
[Authorize(Policy = AuthPolicy.Receiver)]
|
||||||
[HttpPost("auth/logout")]
|
[HttpPost("auth/logout")]
|
||||||
public async Task<IActionResult> LogOutAsync()
|
public async Task<IActionResult> LogOutAsync()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -178,9 +178,9 @@ try
|
|||||||
});
|
});
|
||||||
|
|
||||||
builder.Services.AddAuthorizationBuilder()
|
builder.Services.AddAuthorizationBuilder()
|
||||||
.AddPolicy(AuthPolicy.SenderOrReceiverFullyAuth, policy =>
|
.AddPolicy(AuthPolicy.SenderOrReceiver, policy =>
|
||||||
policy.RequireRole(Role.Sender, Role.Receiver.FullyAuth))
|
policy.RequireRole(Role.Sender, Role.Receiver.FullyAuth))
|
||||||
.AddPolicy(AuthPolicy.ReceiverFullyAuth, policy =>
|
.AddPolicy(AuthPolicy.Receiver, policy =>
|
||||||
policy.RequireRole(Role.Receiver.FullyAuth));
|
policy.RequireRole(Role.Receiver.FullyAuth));
|
||||||
|
|
||||||
// User manager
|
// User manager
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ namespace EnvelopeGenerator.Domain.Constants
|
|||||||
{
|
{
|
||||||
public static class AuthPolicy
|
public static class AuthPolicy
|
||||||
{
|
{
|
||||||
public const string SenderOrReceiverFullyAuth = "SenderOrReceiverFullyAuth";
|
public const string SenderOrReceiver = nameof(SenderOrReceiver) + nameof(AuthPolicy);
|
||||||
public const string ReceiverFullyAuth = "ReceiverFullyAuth";
|
public const string Receiver = nameof(Receiver) + nameof(AuthPolicy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user