Skip to content

Commit 7331ebd

Browse files
committed
Merge branch 'release/v1.1.4'
2 parents ee608c8 + 3f8280a commit 7331ebd

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,3 +348,5 @@ MigrationBackup/
348348

349349
# Ionide (cross platform F# VS Code tools) working folder
350350
.ionide/
351+
352+
Wissance.Authorization/.idea/.idea.Wissance.Authorization/.idea/workspace.xml

Wissance.Authorization/Wissance.Authorization.Tests/OpenId/TestKeyCloakOpenIdAuthenticator.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,18 @@ public void TestTokenRefresh(string userName, string password, string scope, boo
9090
Assert.Equal(token.Session, refreshedToken.Session);
9191
}
9292

93+
/*[Fact]
94+
public void TestGetUserInfoFromBadSsl()
95+
{
96+
IOpenIdAuthenticator authenticator = new KeyCloakOpenIdAuthenticator(_keyCloakOnBadSslConfig , new LoggerFactory());
97+
TokenInfo token = GetToken(authenticator, "adm", "123", TestScope);
98+
Assert.NotNull(token);
99+
Task<UserInfo> getUserInfoTask = authenticator.GetUserInfoAsync(token.AccessToken, token.TokenType);
100+
getUserInfoTask.Wait();
101+
UserInfo actualUserInfo = getUserInfoTask.Result;
102+
Assert.NotNull(actualUserInfo);
103+
}*/
104+
93105
private TokenInfo GetToken(IOpenIdAuthenticator authenticator , string userName, string password, string scope)
94106
{
95107
Task<TokenInfo> authenticateTask = authenticator.AuthenticateAsync(userName, password, scope);

Wissance.Authorization/Wissance.Authorization/OpenId/KeyCloakOpenIdAuthenticator.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)