Option.cs 2.1 KB

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