merken / Prise

A .NET Plugin Framework.
https://merken.github.io/Prise
MIT License
363 stars 40 forks source link

Authorize attribute on plugin controller issue #28

Closed Blankinfinity closed 4 years ago

Blankinfinity commented 4 years ago

Hi

Firstly i just want to say thanks for creating this library, i am finding it very useful. However I have run into a hurdle around authorization on the controllers.

I am adding Authorization in my hosts startup like below:

services.AddAuthorization(options =>
 {
                options.DefaultPolicy = new AuthorizationPolicyBuilder(JwtBearerDefaults.AuthenticationScheme).RequireAuthenticatedUser().Build();
                options.AddPolicy("ApiUser", policy => policy.RequireClaim(Constants.Strings.JwtClaimIdentifiers.Rol, Constants.Strings.JwtClaims.ApiAccess));
            });

And then applying the authorize attribute to the controller :

[Authorize(Policy = "ApiUser")]
    [ResponseCache(NoStore = true)]
    [ApiVersion("1.0")]
    [ApiController]
    [Route("api/[controller]/[action]")]
    public class ServiceNowRequestController : ControllerBase

When i try and hit the api endpoint i get an error of "Request not found. The specified uri does not exist." However if i remove the authorize attribute i can call it fine.

I tried doing AddAuthorization again in the controller bootstrape but this results in the same error.

Is it possible to use Auth with plugins at all, if so can you point me in the right direction.

thanks in advance

Blankinfinity commented 4 years ago

I've also tried adding with ConfigureHostServices but getting the same result.

Blankinfinity commented 4 years ago

Sorry, i'm being an idiot, it is redirecting to an auth page which doesn't exit hence the error.

merken commented 4 years ago

🙌 Thanks for using Prise, and special thanks for fixing this issue on your own!