Option.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 string HttpTrigger { get; set; }
  20. public IList<string> AllowedHosts { get; }
  21. public string Version { get; set; }
  22. public IList<StringSegment> AllowedRedirects
  23. {
  24. get
  25. {
  26. var allowedRedirects = new List<StringSegment>();
  27. if (AllowedHosts?.Count > 0 && !TryProcessHosts(AllowedHosts, allowedRedirects))
  28. {
  29. return allowedRedirects;
  30. }
  31. return allowedRedirects;
  32. }
  33. }
  34. public string JwtSecretKey { get; set; }
  35. public string Authority { get; set; }
  36. public string Audience { get; set; }
  37. public string OSFunction { get; set; }
  38. private bool TryProcessHosts(IEnumerable<string> incoming, IList<StringSegment> results)
  39. {
  40. foreach (var entry in incoming)
  41. {
  42. // Punycode. Http.Sys requires you to register Unicode hosts, but the headers contain punycode.
  43. var host = new HostString(entry).ToUriComponent();
  44. if (IsTopLevelWildcard(host)) continue;
  45. if (!results.Contains(host, StringSegmentComparer.OrdinalIgnoreCase)) results.Add(host);
  46. }
  47. return true;
  48. }
  49. private bool IsTopLevelWildcard(string host)
  50. {
  51. return (string.Equals("*", host, StringComparison.Ordinal) // HttpSys wildcard
  52. || string.Equals("[::]", host, StringComparison.Ordinal) // Kestrel wildcard, IPv6 Any
  53. || string.Equals("0.0.0.0", host, StringComparison.Ordinal)); // IPv4 Any
  54. }
  55. }
  56. }