I have implemented a middle ware that would be executed on every route. On the basis of the absence of a claim in the identity, I would like to restrict the route access. Below is what I'm able to implement now
app.Map(new PathString(Configuration["APIRoutes"]), HandleCustomAuthentication);
// Function
private void HandleCustomAuthentication(IApplicationBuilder app)
{
app.Run(async (context) =>
{
var route = context.GetRouteData();
var token = context.Request.Headers["Authorization"].ToString().Split(" ")[1];
if (context.Request.Headers.ContainsKey("xyz") && context.Request.Headers["xyz"] !="0" )
{
// No idea how to make sure if this condition is met run the particular route.
}
});
}
Can someone guide how to do it?
P.S: I'm using dot net core 2.0