iayti / CleanArchitecture

ASP.NET Core 6 Web API Clean Architecture Solution Template
MIT License
682 stars 124 forks source link

Authorize with Policy show 'The type or namespace could not be found' #45

Open chuki2 opened 2 years ago

chuki2 commented 2 years ago

Hi, I facing the issues with Authorize attribute when using policy

Since in your code using custom authorize class, so I unable to implement policy here.

If using Microsoft.AspNetCore.Authorization.AuthorizeAttribute, then the authorization is not working.

Example

//Need use this, or else show an error 'The type or namespace could not be found'
using AuthorizeAttribute = Microsoft.AspNetCore.Authorization.AuthorizeAttribute;

[HttpPost]
[Route("uom")]
[Authorize(Policy = "user.read.policy")] // Is not working
[ProducesResponseType(typeof(ServiceResult<ItemUomDto>), (int)HttpStatusCode.OK)]
public async Task<ActionResult<ServiceResult<ItemUomDto>>> Create([FromBody] CreateItemUomCommand command)
{
     return Ok(await Mediator.Send(command));
}

Any idea how we can solve?