@@ -42,7 +42,12 @@ public async Task<UserInfo> GetUserInfoAsync(string accessToken, string tokenTyp
4242 try
4343 {
4444 string url = KeyCloakHelper . GetUserInfoUri ( _config . BaseUrl , _config . Realm ) ;
45- using ( HttpClient httpClient = new HttpClient ( ) )
45+ HttpClientHandler handler = new HttpClientHandler ( )
46+ {
47+ ClientCertificateOptions = ClientCertificateOption . Manual ,
48+ ServerCertificateCustomValidationCallback = ( httpRequestMessage , cert , cetChain , policyErrors ) => true
49+ } ;
50+ using ( HttpClient httpClient = new HttpClient ( handler ) )
4651 {
4752 httpClient . DefaultRequestHeaders . Authorization = new AuthenticationHeaderValue ( tokenType , accessToken ) ;
4853 HttpResponseMessage response = await httpClient . GetAsync ( url ) ;
@@ -84,7 +89,13 @@ private async Task<TokenInfo> GetTokenAsync(string realm, FormUrlEncodedContent
8489 try
8590 {
8691 string url = KeyCloakHelper . GetTokenUri ( _config . BaseUrl , realm ) ;
87- using ( HttpClient httpClient = new HttpClient ( ) )
92+ HttpClientHandler handler = new HttpClientHandler ( )
93+ {
94+ ClientCertificateOptions = ClientCertificateOption . Manual ,
95+ ServerCertificateCustomValidationCallback = ( httpRequestMessage , cert , cetChain , policyErrors ) => true
96+ } ;
97+
98+ using ( HttpClient httpClient = new HttpClient ( handler ) )
8899 {
89100 HttpResponseMessage response = await httpClient . PostAsync ( url , formContent ) ;
90101 string responseBody = await response . Content . ReadAsStringAsync ( ) ;
@@ -111,7 +122,7 @@ private async Task<TokenInfo> GetTokenAsync(string realm, FormUrlEncodedContent
111122 return null ;
112123 }
113124 }
114-
125+
115126 private readonly KeyCloakServerConfig _config ;
116127 private readonly ILogger < KeyCloakOpenIdAuthenticator > _logger ;
117128 }
0 commit comments