Created
October 6, 2025 09:47
-
-
Save uzbekdev1/c3d10119c9cf49668dd6cd6fb04309ce to your computer and use it in GitHub Desktop.
authenticator validation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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