Option.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using Microsoft.AspNetCore.Authentication.OAuth;
  2. using Microsoft.AspNetCore.Http;
  3. using Microsoft.Extensions.Primitives;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Threading.Tasks;
  8. namespace TEAMModelOS.Models
  9. {
  10. public class Option
  11. {
  12. public Option()
  13. {
  14. }
  15. public string Location { get; set; }
  16. public string LocationNum { get; set; }
  17. public string BlobDomain { get; set; }
  18. public string HostName { get; set; }
  19. public IList<string> AllowedHosts { get; }
  20. public IList<StringSegment> AllowedRedirects
  21. {
  22. get
  23. {
  24. var allowedRedirects = new List<StringSegment>();
  25. if (AllowedHosts?.Count > 0 && !TryProcessHosts(AllowedHosts, allowedRedirects))
  26. {
  27. return allowedRedirects;
  28. }
  29. return allowedRedirects;
  30. }
  31. }
  32. public string JwtSecretKey { get; set; }
  33. public string Authority { get; set; }
  34. public string Audience { get; set; }
  35. public string OSFunction { get; set; }
  36. private bool TryProcessHosts(IEnumerable<string> incoming, IList<StringSegment> results)
  37. {
  38. foreach (var entry in incoming)
  39. {
  40. // Punycode. Http.Sys requires you to register Unicode hosts, but the headers contain punycode.
  41. var host = new HostString(entry).ToUriComponent();
  42. if (IsTopLevelWildcard(host)) continue;
  43. if (!results.Contains(host, StringSegmentComparer.OrdinalIgnoreCase)) results.Add(host);
  44. }
  45. return true;
  46. }
  47. private bool IsTopLevelWildcard(string host)
  48. {
  49. return (string.Equals("*", host, StringComparison.Ordinal) // HttpSys wildcard
  50. || string.Equals("[::]", host, StringComparison.Ordinal) // Kestrel wildcard, IPv6 Any
  51. || string.Equals("0.0.0.0", host, StringComparison.Ordinal)); // IPv4 Any
  52. }
  53. }
  54. }