question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug][FE 5.3.0/.1] Roles Policy calls throw "AuthorizationPolicy named: 'epPolicy:<EndPointName>' was not found."

See original GitHub issue

Expected 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

  1. As package, use FastEndpoints 5.3.1
  2. Write an Endpoint with requests using FromClaim and a non-FromClaimresponse (same parameters) and have the Roles(<role>) in Configure
  3. Write the endpoint
  4. Trigger the endpoint written with the proper role
  5. 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:closed
  • Created a year ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
EelcoLoscommented, Nov 1, 2022

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.

0reactions
dj-nitehawkcommented, Nov 1, 2022

so all good then?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found