Eventuous / eventuous

Event Sourcing library for .NET
https://eventuous.dev
Apache License 2.0
442 stars 70 forks source link

MapEventuousSpyglass interferes with UseAuthentication and UseAuthorization #263

Closed matt-lethargic closed 11 months ago

matt-lethargic commented 1 year ago

Describe the bug When applying authentication to my API I get 500 error with

 Endpoint Test.Controllers.Customers.CreateCustomerController.CreateCustomer (Test) contains authorization metadata, but a middleware was not found that supports authorization.
Configure your application startup by adding app.UseAuthorization() in the application startup code. If there are calls to app.UseRouting() and app.UseEndpoints(...), the call to app.UseAuthorization() must go between them.

To Reproduce Steps to reproduce the behavior: Create API and have the code below

app.UseAuthentication();
app.UseAuthorization();
app.MapEventuousSpyglass();

Expected behavior Authentication works and spyglass works

Additional Context Looking at the code in MapEventuousSpyglass() you call app.UseRouting then app.UseEndpoints a work around I've found for now is to call app.UseRouting in my program.cs file

app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.MapEventuousSpyglass();
alexeyzimarev commented 1 year ago

I guess the "solution" would be to remove UseRouting from the extension because people do it anyway, and it must be done in a correct order.