|
1 | 1 | using System.Globalization; |
2 | 2 | using System.Net; |
3 | | -using System.Net.Security; |
4 | 3 | using System.Reflection; |
5 | | -using System.Security.Authentication; |
6 | 4 | using System.Security.Claims; |
7 | 5 | using System.Threading.RateLimiting; |
8 | 6 | using Htmx.TagHelpers; |
|
38 | 36 | using Intersect.Server.Web.Controllers.Api; |
39 | 37 | using Intersect.Server.Web.Controllers.AssetManagement; |
40 | 38 | using Intersect.Server.Web.Types.Chat; |
41 | | -using Microsoft.AspNetCore.Server.Kestrel.Core; |
| 39 | +using Microsoft.AspNetCore.Http.Features; |
| 40 | +using MyCSharp.HttpUserAgentParser.AspNetCore.DependencyInjection; |
| 41 | +using MyCSharp.HttpUserAgentParser.MemoryCache.DependencyInjection; |
42 | 42 |
|
43 | 43 | #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously |
44 | 44 |
|
@@ -120,6 +120,8 @@ internal partial class ApiService : ApplicationService<ServerContext, IApiServic |
120 | 120 | } |
121 | 121 | ); |
122 | 122 |
|
| 123 | + builder.Services.AddHttpUserAgentMemoryCachedParser().AddHttpUserAgentParserAccessor(); |
| 124 | + |
123 | 125 | builder.Services.AddRateLimiter( |
124 | 126 | rateLimiterOptions => |
125 | 127 | { |
@@ -170,7 +172,9 @@ internal partial class ApiService : ApplicationService<ServerContext, IApiServic |
170 | 172 | CookieAuthenticationDefaults.AuthenticationScheme, |
171 | 173 | options => |
172 | 174 | { |
173 | | - options.ForwardChallenge = JwtBearerDefaults.AuthenticationScheme; |
| 175 | + // Commenting this out fixes no redirect |
| 176 | + // Uncommenting fixed something else, but I can't remember what it was |
| 177 | + // options.ForwardChallenge = JwtBearerDefaults.AuthenticationScheme; |
174 | 178 | options.Events.OnSignedIn += async (context) => { }; |
175 | 179 | options.Events.OnSigningIn += async (context) => { }; |
176 | 180 | options.Events.OnSigningOut += async (context) => { }; |
@@ -203,8 +207,12 @@ internal partial class ApiService : ApplicationService<ServerContext, IApiServic |
203 | 207 | context.ShouldRenew = true; |
204 | 208 | context.ReplacePrincipal(updatedPrincipal); |
205 | 209 | }; |
206 | | - options.Events.OnRedirectToLogin += async (context) => { }; |
207 | | - options.Events.OnRedirectToAccessDenied += async (context) => { }; |
| 210 | + options.Events.OnRedirectToLogin += async (context) => |
| 211 | + { |
| 212 | + }; |
| 213 | + options.Events.OnRedirectToAccessDenied += async (context) => |
| 214 | + { |
| 215 | + }; |
208 | 216 | options.Events.OnRedirectToLogout += async (context) => { }; |
209 | 217 | options.Events.OnRedirectToReturnUrl += async (context) => { }; |
210 | 218 | options.ExpireTimeSpan = TimeSpan.FromSeconds(10); |
@@ -486,30 +494,6 @@ internal partial class ApiService : ApplicationService<ServerContext, IApiServic |
486 | 494 | app.UseIntersectRequestLogging(configuration.RequestLogLevel); |
487 | 495 | } |
488 | 496 |
|
489 | | - app.UseStaticFiles(); |
490 | | - |
491 | | - // Unreadable if it LINQs it... |
492 | | - // ReSharper disable once ForeachCanBePartlyConvertedToQueryUsingAnotherGetEnumerator |
493 | | - foreach (var (sourcePath, requestPath) in configuration.StaticFilePaths) |
494 | | - { |
495 | | - var pathToRoot = Path.Combine(builder.Environment.ContentRootPath, sourcePath); |
496 | | - if (!Directory.Exists(pathToRoot)) |
497 | | - { |
498 | | - Directory.CreateDirectory(pathToRoot); |
499 | | - } |
500 | | - |
501 | | - app.UseStaticFiles( |
502 | | - new StaticFileOptions |
503 | | - { |
504 | | - FileProvider = new PhysicalFileProvider( |
505 | | - pathToRoot, |
506 | | - ExclusionFilters.Sensitive |
507 | | - ), |
508 | | - RequestPath = requestPath ?? string.Empty, |
509 | | - } |
510 | | - ); |
511 | | - } |
512 | | - |
513 | 497 | app.UseRouting(); |
514 | 498 |
|
515 | 499 | app.UseAuthentication(); |
@@ -549,6 +533,39 @@ internal partial class ApiService : ApplicationService<ServerContext, IApiServic |
549 | 533 | app.UseResponseCaching(); |
550 | 534 | app.UseOutputCache(); |
551 | 535 |
|
| 536 | + |
| 537 | + StaticFileOptions staticFileOptions = new() |
| 538 | + { |
| 539 | + HttpsCompression = HttpsCompressionMode.Compress, |
| 540 | + ServeUnknownFileTypes = true, |
| 541 | + }; |
| 542 | + |
| 543 | + app.UseStaticFiles(staticFileOptions); |
| 544 | + |
| 545 | + // Unreadable if it LINQs it... |
| 546 | + // ReSharper disable once ForeachCanBePartlyConvertedToQueryUsingAnotherGetEnumerator |
| 547 | + foreach (var (sourcePath, requestPath) in configuration.StaticFilePaths) |
| 548 | + { |
| 549 | + var pathToRoot = Path.Combine(builder.Environment.ContentRootPath, sourcePath); |
| 550 | + if (!Directory.Exists(pathToRoot)) |
| 551 | + { |
| 552 | + Directory.CreateDirectory(pathToRoot); |
| 553 | + } |
| 554 | + |
| 555 | + app.UseStaticFiles( |
| 556 | + new StaticFileOptions |
| 557 | + { |
| 558 | + FileProvider = new PhysicalFileProvider( |
| 559 | + pathToRoot, |
| 560 | + ExclusionFilters.Sensitive |
| 561 | + ), |
| 562 | + HttpsCompression = HttpsCompressionMode.Compress, |
| 563 | + RequestPath = requestPath ?? string.Empty, |
| 564 | + ServeUnknownFileTypes = true, |
| 565 | + } |
| 566 | + ); |
| 567 | + } |
| 568 | + |
552 | 569 | app.UseAuthorization(); |
553 | 570 |
|
554 | 571 | app.MapHtmxAntiforgeryScript(); |
|
0 commit comments