Skip to content

Instantly share code, notes, and snippets.

@uzbekdev1
Created October 6, 2025 09:47
Show Gist options
  • Save uzbekdev1/c3d10119c9cf49668dd6cd6fb04309ce to your computer and use it in GitHub Desktop.
Save uzbekdev1/c3d10119c9cf49668dd6cd6fb04309ce to your computer and use it in GitHub Desktop.
authenticator validation
public class GlobalMiddleware
{
private readonly RequestDelegate _next;
public GlobalMiddleware(RequestDelegate next )
{
_next = next;
}
public async Task Invoke(HttpContext context)
{
try
{
await _next(context);
if (context.Response.Headers.TryGetValue("www-authenticate", out var authError))
{
context.Response.Headers.Remove("www-authenticate");
throw new Exception("Authentication failed, please check your token.");
}
}
catch (Exception exception)
{
...
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment