Skip to content

Easy Check Attribute

Furkan Güngör edited this page Oct 16, 2021 · 1 revision

Summary

Use the EasyCheck attribute to check automatically.


Step 1 : Install Package

Install EasyPermissionManagement.AspNetCore from Nuget Package

Step 2 : Add Attribute

/// <summary>
/// Identifier Permission Endpoints
/// </summary>
[ApiController]
[Route("[controller]")]
public class IdentifierPermissionController : ControllerBase
{
    private readonly IPermissionProvider permissionProvider;

    /// <summary>
    /// Ctor
    /// </summary>
    /// <param name="permissionProvider">
    /// Assign or remove permissions to your data.
    /// </param>
    public IdentifierPermissionController(IPermissionProvider permissionProvider)
    {
        this.permissionProvider = permissionProvider;
    }

    /// <summary>
    /// Authorize Check For User Identifier Endpoint
    /// </summary>
    /// <remarks>
    /// The authorization status of the id information coming over the route will be determined by the User Identifier method.
    /// This endpoint will check lead.read permission with User Identifier method.
    /// </remarks>
    /// <returns></returns>
    [HttpGet("users/{id}/authorize")]
    [EasyCheck("lead.read", "User")]
    public IActionResult AuthorizeCheck([FromRoute] string id)
    {
        return Ok("Authorize ✅ : " + id);
    }
}

EasyCheckAttribute performs checks using the key and Identifier method you define. If permission is granted for the request, the request continues its lifecycle. However, if permission is not assigned for the request, the request lifecycle is interrupted and the user receives a response with a 403 status code.

EasyCheckAttribute dynamically finds and runs the identifier method you defined.

Welcome to the EasyPermissionManagement wiki!

Topics:

Clone this wiki locally