Skip to content

Commit 53524f2

Browse files
Refactors loading cert in EntraMockResponsePlugin. Closes #1610 (#1612)
* Refactors loading cert in EntraMockResponsePlugin. Closes #1610 * Removes dead null check after GetRequiredService
1 parent 9c2b0d2 commit 53524f2

1 file changed

Lines changed: 5 additions & 8 deletions

File tree

DevProxy.Plugins/Mocking/EntraMockResponsePlugin.cs

Lines changed: 5 additions & 8 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,14 @@ 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-
{
156-
return [];
157-
}
158-
155+
var cert = serviceProvider.GetRequiredService<X509Certificate2>();
159156
var collection = new X509Certificate2Collection
160157
{
161-
certificate
158+
cert
162159
};
163160

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

0 commit comments

Comments
 (0)