Skip to content

Commit 7e05281

Browse files
Refactors loading cert in EntraMockResponsePlugin. Closes #1610
1 parent d0bff06 commit 7e05281

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

DevProxy.Plugins/Mocking/EntraMockResponsePlugin.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Microsoft.Extensions.Logging;
1010
using System.Security.Cryptography.X509Certificates;
1111
using System.Text;
12+
using Microsoft.Extensions.DependencyInjection;
1213
using System.Text.Json;
1314
using System.Text.Json.Serialization;
1415
using System.Text.RegularExpressions;
@@ -39,7 +40,7 @@ public sealed class EntraMockResponsePlugin(
3940
HttpClient httpClient,
4041
ILogger<EntraMockResponsePlugin> logger,
4142
ISet<UrlToWatch> urlsToWatch,
42-
X509Certificate2 certificate,
43+
IServiceProvider serviceProvider,
4344
IProxyConfiguration proxyConfiguration,
4445
IConfigurationSection pluginConfigurationSection) :
4546
MockResponsePlugin(
@@ -147,18 +148,19 @@ private void UpdateIdToken(ref string body, ref bool changed)
147148
changed = true;
148149
}
149150

150-
private string GetKeyId() => certificate.Thumbprint ?? "";
151+
private string GetKeyId() => serviceProvider.GetRequiredService<X509Certificate2>().Thumbprint ?? "";
151152

152153
private List<string> GetCertificateChain()
153154
{
154-
if (certificate is null)
155+
var cert = serviceProvider.GetRequiredService<X509Certificate2>();
156+
if (cert is null)
155157
{
156158
return [];
157159
}
158160

159161
var collection = new X509Certificate2Collection
160162
{
161-
certificate
163+
cert
162164
};
163165

164166
var certificateChain = new List<string>();

0 commit comments

Comments
 (0)