5
5
*/
6
6
7
7
using System . ComponentModel ;
8
+ using System . Security . Cryptography . X509Certificates ;
8
9
using Microsoft . Extensions . Options ;
10
+ using OpenIddict . Client . SystemNetHttp ;
11
+ using static OpenIddict . Client . WebIntegration . OpenIddictClientWebIntegrationConstants ;
9
12
10
13
namespace OpenIddict . Client . WebIntegration ;
11
14
@@ -14,7 +17,8 @@ namespace OpenIddict.Client.WebIntegration;
14
17
/// </summary>
15
18
[ EditorBrowsable ( EditorBrowsableState . Advanced ) ]
16
19
public sealed partial class OpenIddictClientWebIntegrationConfiguration : IConfigureOptions < OpenIddictClientOptions > ,
17
- IPostConfigureOptions < OpenIddictClientOptions >
20
+ IPostConfigureOptions < OpenIddictClientOptions > ,
21
+ IPostConfigureOptions < OpenIddictClientSystemNetHttpOptions >
18
22
{
19
23
/// <inheritdoc/>
20
24
public void Configure ( OpenIddictClientOptions options )
@@ -47,6 +51,38 @@ public void PostConfigure(string? name, OpenIddictClientOptions options)
47
51
} ) ;
48
52
}
49
53
54
+ /// <inheritdoc/>
55
+ public void PostConfigure ( string ? name , OpenIddictClientSystemNetHttpOptions options )
56
+ {
57
+ if ( options is null )
58
+ {
59
+ throw new ArgumentNullException ( nameof ( options ) ) ;
60
+ }
61
+
62
+ // Override the default/user-defined selectors to support attaching TLS client
63
+ // certificates that don't meet the requirements enforced by default by OpenIddict.
64
+ options . SelfSignedTlsClientAuthenticationCertificateSelector = CreateSelector ( options . SelfSignedTlsClientAuthenticationCertificateSelector ) ;
65
+ options . TlsClientAuthenticationCertificateSelector = CreateSelector ( options . TlsClientAuthenticationCertificateSelector ) ;
66
+
67
+ static Func < OpenIddictClientRegistration , X509Certificate2 ? > CreateSelector ( Func < OpenIddictClientRegistration , X509Certificate2 ? > selector )
68
+ => registration =>
69
+ {
70
+ var certificate = registration . ProviderType switch
71
+ {
72
+ ProviderTypes . ProSantéConnect => registration . GetProSantéConnectSettings ( ) . SigningCertificate ,
73
+
74
+ _ => null
75
+ } ;
76
+
77
+ if ( certificate is not null )
78
+ {
79
+ return certificate ;
80
+ }
81
+
82
+ return selector ( registration ) ;
83
+ } ;
84
+ }
85
+
50
86
/// <summary>
51
87
/// Amends the registration with the provider-specific configuration logic.
52
88
/// </summary>
0 commit comments