[Bug][FE 5.3.0/.1] Roles Policy calls throw "AuthorizationPolicy named: 'epPolicy:<EndPointName>' was not found."
See original GitHub issueExpected Behavior
To have a rolecheck on a user, without AuthorizationPolicy
.
Actual Behavior
{
"status": "Internal Server Error!",
"code": 500,
"reason": "The AuthorizationPolicy named: 'epPolicy:Api.EndPoints.Folders.DeleteFolderEndpoint' was not found.",
"note": "See application log for stack trace."
}
Steps to Reproduce the Problem
- As package, use FastEndpoints 5.3.1
- Write an Endpoint with requests using
FromClaim
and a non-FromClaim
response (same parameters) and have theRoles(<role>)
in Configure - Write the endpoint
- Trigger the endpoint written with the proper role
- You get the exception below
public class DeleteFolderEndpoint : EndpointWithMapping<DeleteFolderEndpointRequest, EmptyResponse, DeleteFolderCommand>
{
private readonly DeleteFolderCommandHandler _commandHandler;
public DeleteFolderEndpoint(DeleteFolderCommandHandler commandHandler)
{
_commandHandler = commandHandler;
}
public override void Configure()
{
Verbs(Http.DELETE);
Routes("/folders/{FolderId}");
Description(x =>
{
x.WithName("deleteFolder");
x.Produces(StatusCodes.Status204NoContent);
x.Produces(StatusCodes.Status403Forbidden);
x.ProducesValidationProblem();
x.ProducesProblemFE(StatusCodes.Status500InternalServerError);
}, clearDefaults: true);
Roles(Roles.ApplicatieBeheerRole);
}
public override async Task HandleAsync(DeleteFolderEndpointRequest req, CancellationToken ct)
{
var command = MapToEntity(req);
var validationResults = await _commandHandler.HandleAsync(command);
foreach (var error in validationResults.Errors) AddError(error.ErrorMessage);
ThrowIfAnyErrors();
await SendNoContentAsync(ct);
}
public override DeleteFolderCommand MapToEntity(DeleteFolderEndpointRequest request)
{
return new DeleteFolderCommand
{
FolderId = request.FolderId,
CompanyId = request.CompanyId,
};
}
}
FastEndpoints.ExceptionHandler[0]
=================================
HTTP: DELETE /api/folders/{FolderId}
TYPE: InvalidOperationException
REASON: The AuthorizationPolicy named: 'epPolicy: Api.EndPoints.Folders.DeleteFolderEndpoint' was not found.
---------------------------------
at Microsoft.AspNetCore.Authorization.AuthorizationPolicy.CombineAsync(IAuthorizationPolicyProvider policyProvider, IEnumerable`1 authorizeData)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Api.Supports.ProxyForForge.InvokeAsync(HttpContext context, RequestDelegate next) in apps\api\Supports\ProxyForForge.cs:line 30
at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass6_1.<<UseMiddlewareInterface>b__1>d.MoveNext()
--- End of stack trace from previous location ---
at Api.Supports.RoleCheckMiddleware.Invoke(HttpContext httpContext) in apps\api\Supports\RoleCheckMiddleware.cs:line 38
at Program.<>c.<<<Main>$>b__0_3>d.MoveNext() in apps\api\Program.cs:line 59
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Shared.Startup.StrictSameSiteExternalAuthenticationMiddleware.Invoke(HttpContext ctx) in libs\shared\startup\StrictSameSiteExternalAuthenticationMiddleware.cs:line 51
at Microsoft.Azure.AppConfiguration.AspNetCore.AzureAppConfigurationRefreshMiddleware.InvokeAsync(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)
Issue Analytics
- State:
- Created a year ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
The AuthorizationPolicy named: 'Admin' was not found
I am trying to create a controller that can only be accessed by 'Admin', but get the following error. An unhandled exception occurred...
Read more >I can't use ASP.NET Identity and JWT autentication at the ...
Requests to the web application are authorized but requests to Web API fail with "The AuthorizationPolicy named: 'Bearer' was not found."? Or ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
we’ll be running all kinds of regression tests to see if all things remain operational. For now, yes, all is good. I’ll reopen if need be.
so all good then?