Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CU-8687yhbz5 adding handler #138

Merged
merged 1 commit into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading