I am trying to write a middleware which executes between authentication and authorization.
I've registered that middleware between these the two authXYZ:
app.UseAuthentication();
app.UseCustomMiddlerware();
app.UseAuthorization();
But I cannot get an authenticated user in my CustomMiddlerware.
When I deleted the app.UseAuthentication() statement then I found out that AuthenticationHandler still runs, and an authenticated user is available only after app.UseAuthorization().
So, here are my questions:
- Can I only use
app.UseAuthorization()instead of using bothapp.UseAuthentication()andapp.UseAuthorization()?
1.1 What are the differences? - Are authentication and authorization triggered together?
2.1 Is there any way to insert a middlerware between them?