Advertisement
Guest User

Untitled

a guest
Feb 20th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. public class Program
  2. {
  3. public static void Main(string[] args)
  4. {
  5. var config = new ConfigurationBuilder()
  6. .AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(),"hosting.json"), optional: false)
  7. .Build();
  8.  
  9. var useHttps = false;
  10.  
  11. bool.TryParse(config !=null ? config["useHttps"] : "false", out useHttps);
  12.  
  13. IWebHost host = null;
  14. if (useHttps)
  15. {
  16. var fileInfo = new FileInfo(config["certName"]);
  17. X509Certificate2 cert = new X509Certificate2(fileInfo.FullName, config["certPwd"]);
  18.  
  19. host = new WebHostBuilder()
  20. .UseContentRoot(Directory.GetCurrentDirectory())
  21. .UseStartup<Startup>()
  22. .UseKestrel(options =>
  23. {
  24. options.Listen(IPAddress.Loopback, 5000);
  25. options.Listen(IPAddress.Any, 4430, listenOptions =>
  26. {
  27. listenOptions.UseHttps(cert);
  28. });
  29. })
  30. .UseIISIntegration()
  31. .Build();
  32. }
  33. else
  34. {
  35. host = new WebHostBuilder()
  36. .UseStartup<Startup>()
  37. .UseKestrel()
  38. .UseContentRoot(Directory.GetCurrentDirectory())
  39. .UseIISIntegration()
  40. .UseUrls(config["url"])
  41. .Build();
  42.  
  43. }
  44. host.Run();
  45.  
  46.  
  47. }
  48. }
  49.  
  50. public class NetworkExtensions
  51. {
  52. public static IConfiguration Configuration { get; set; }
  53. public static ILogger Log { get; set; }
  54.  
  55. /// <summary>
  56. /// Flurl to get api
  57. /// </summary>
  58. /// <typeparam name="T"></typeparam>
  59. /// <param name="requestDto"></param>
  60. /// <param name="rateLimit">This param is used to Perform OKTA api Retry </param>
  61. /// <returns></returns>
  62. public static async Task<T> Get<T>(OktaRequestDto requestDto, OKTARateLimit rateLimit = null)
  63. {
  64. using (MiniProfiler.Current.Step("Okta : Get"))
  65. {
  66.  
  67. // OKTA code execution starts here.
  68. string url = requestDto.BaseUrl
  69. .AppendPathSegment(requestDto.ApiName + requestDto.Query);
  70.  
  71. // Handle all querystring append.
  72. if (requestDto.QueryStrings != null && requestDto.QueryStrings.Count > 0)
  73. {
  74. foreach (var querystring in requestDto.QueryStrings.Keys)
  75. {
  76. //FLURL is encoding the value, To ensure the value is passed correct, added true param to stop default behavior
  77. url = url.SetQueryParam(querystring, requestDto.QueryStrings[querystring], true);
  78. }
  79. }
  80.  
  81. var response = await url.WithHeader("Authorization", requestDto.ApiKey).GetJsonAsync<T>();
  82.  
  83.  
  84. Log.Information("response => " + JsonConvert.SerializeObject(response));
  85.  
  86. return response;
  87.  
  88. catch (FlurlHttpException ex)
  89. {
  90. // there is an OKTA exception, return the default value, The exception is captured in the FLURLConfig
  91. OneLoginException ole = new OneLoginException(ex, requestDto);
  92. throw ole;
  93.  
  94. }
  95. catch (Exception ex)
  96. {
  97. throw ex;
  98. }
  99. }
  100. }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement