Skip to content

Commit

Permalink
CU-8687yhbz5 adding handler
Browse files Browse the repository at this point in the history
  • Loading branch information
ucswift committed Jun 22, 2024
1 parent 93ce4cb commit 8502166
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
6 changes: 5 additions & 1 deletion Web/Resgrid.Web.Eventing/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void ConfigureServices(IServiceCollection services)

if (Config.ApiConfig.BypassSslChecks)
{
services.AddHttpClient("Name")
services.AddHttpClient("ByPassSSLHttpClient")
.ConfigurePrimaryHttpMessageHandler(() =>
{
var handler = new HttpClientHandler
Expand All @@ -115,6 +115,10 @@ public void ConfigureServices(IServiceCollection services)
return handler;
});
}
else
{
services.AddHttpClient("ByPassSSLHttpClient");
}

services.AddCors();

Expand Down
6 changes: 5 additions & 1 deletion Web/Resgrid.Web.ServicesCore/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void ConfigureServices(IServiceCollection services)

if (Config.ApiConfig.BypassSslChecks)
{
services.AddHttpClient("Name")
services.AddHttpClient("ByPassSSLHttpClient")
.ConfigurePrimaryHttpMessageHandler(() =>
{
var handler = new HttpClientHandler
Expand All @@ -138,6 +138,10 @@ public void ConfigureServices(IServiceCollection services)
return handler;
});
}
else
{
services.AddHttpClient("ByPassSSLHttpClient");
}

services.AddScoped<IUserStore<Model.Identity.IdentityUser>, IdentityUserStore>();
services.AddScoped<IRoleStore<Model.Identity.IdentityRole>, IdentityRoleStore>();
Expand Down
11 changes: 9 additions & 2 deletions Web/Resgrid.WebCore/Helpers/ApiAuthHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using IdentityModel.Client;
using CommonServiceLocator;
using IdentityModel.Client;
using Microsoft.AspNetCore.Http;
using Newtonsoft.Json;
using System;
using System.Dynamic;
Expand All @@ -10,9 +12,14 @@ namespace Resgrid.WebCore.Helpers
{
public class ApiAuthHelper
{
private static IHttpClientFactory _httpClientFactory;

public static async Task<string> GetBearerApiTokenAsync(string username, string password)
{
HttpClient client = new HttpClient();
if (_httpClientFactory == null)
_httpClientFactory = ServiceLocator.Current.GetInstance<IHttpClientFactory>();

HttpClient client = _httpClientFactory.CreateClient("ByPassSSLHttpClient");
// Retrieve the OpenIddict server configuration document containing the endpoint URLs.
var configuration = await client.GetDiscoveryDocumentAsync(Config.SystemBehaviorConfig.ResgridApiBaseUrl);
if (configuration.IsError)
Expand Down
6 changes: 5 additions & 1 deletion Web/Resgrid.WebCore/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void ConfigureServices(IServiceCollection services)

if (Config.ApiConfig.BypassSslChecks)
{
services.AddHttpClient("Name")
services.AddHttpClient("ByPassSSLHttpClient")
.ConfigurePrimaryHttpMessageHandler(() =>
{
var handler = new HttpClientHandler
Expand All @@ -120,6 +120,10 @@ public void ConfigureServices(IServiceCollection services)
return handler;
});
}
else
{
services.AddHttpClient("ByPassSSLHttpClient");
}

services.AddScoped<IUserStore<Model.Identity.IdentityUser>, IdentityUserStore>();
services.AddScoped<IRoleStore<Model.Identity.IdentityRole>, IdentityRoleStore>();
Expand Down

0 comments on commit 8502166

Please sign in to comment.