-
Notifications
You must be signed in to change notification settings - Fork 2
Description
//app.Use((context, next) =>
//{
// IAntiforgery antiforgery = app.Services.GetServices().FirstOrDefault();
// var user = context.User.Identity.Name;
// if (context.Request.Path.Value.Equals("/"))
// {
// return next(context);
// }
// if (!context.Request.Path.Value.EndsWith("login", StringComparison.InvariantCultureIgnoreCase))
// {
// var theaders = context.Request.Headers["X-CSRF-TOKEN-HEADER"];
// string theader = "";
// if (theaders.Count() > 0)
// {
// theader = theaders[0];
// }
// System.Diagnostics.Debug.WriteLine($"Path={context.Request.Path.Value} User={user}, Token={theader}");
// try
// {
// antiforgery.ValidateRequestAsync(context);
// }
// catch (AntiforgeryValidationException ex)
// {
// context.Response.StatusCode = 400;
// System.Diagnostics.Debug.WriteLine($"Invalid antiforgery token: {ex.Message}");
// throw new BadHttpRequestException($"Invalid antiforgery token: {ex.Message}");
// }
// }
// var tokens = antiforgery.GetAndStoreTokens(context);
// System.Diagnostics.Debug.WriteLine($"Path={context.Request.Path.Value} User={user}, NewToken={tokens.RequestToken}");
// context.Response.Cookies.Append("XSRF-TOKEN", tokens.RequestToken, new CookieOptions() { HttpOnly = false });
// return next(context);
//});