Helpers/GcMsalHttpClientFactory.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
using Microsoft.Identity.Client;
using System.Net; using System.Net.Http; public class GcMsalHttpClientFactory : Microsoft.Identity.Client.IMsalHttpClientFactory { static HttpClient _httpClient; protected GcMsalHttpClientFactory(WebProxy proxy, string productVersion, bool useDefaultCredentials = false) { if (null == _httpClient) { var httpClientHandler = new HttpClientHandler() { UseDefaultCredentials = useDefaultCredentials }; if (null != proxy) { httpClientHandler.Proxy = proxy; httpClientHandler.UseProxy = true; } _httpClient = new HttpClient(httpClientHandler); _httpClient.DefaultRequestHeaders.UserAgent.Add(new System.Net.Http.Headers.ProductInfoHeaderValue("AadAuthenticationFactory", productVersion)); } } public HttpClient GetHttpClient() { return _httpClient; } //PS5 has trouble to get interface from object instance public static Microsoft.Identity.Client.IMsalHttpClientFactory Create(WebProxy proxy, string productVersion, bool useDefaultCredentials = false) { return new GcMsalHttpClientFactory(proxy, productVersion,useDefaultCredentials); } } |