#1 : Test de modi.
This commit is contained in:
@@ -99,6 +99,48 @@ static void AddKeycloakRolesFromAccessToken(ClaimsIdentity identity, string? acc
|
|||||||
AddKeycloakRolesFromJson(identity, payload, clientId);
|
AddKeycloakRolesFromJson(identity, payload, clientId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static async Task LogKeycloakMetadataAsync(IConfiguration configuration, Logger logger)
|
||||||
|
{
|
||||||
|
var metadataAddress = configuration["Keycloak:MetadataAddress"];
|
||||||
|
if (string.IsNullOrWhiteSpace(metadataAddress))
|
||||||
|
{
|
||||||
|
var authority = configuration["Keycloak:Authority"]?.TrimEnd('/');
|
||||||
|
metadataAddress = string.IsNullOrWhiteSpace(authority)
|
||||||
|
? null
|
||||||
|
: authority + "/.well-known/openid-configuration";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(metadataAddress))
|
||||||
|
{
|
||||||
|
logger.Warn("Diagnostic Keycloak ignore : aucune adresse de metadata configuree.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var handler = new HttpClientHandler
|
||||||
|
{
|
||||||
|
ServerCertificateCustomValidationCallback =
|
||||||
|
HttpClientHandler.DangerousAcceptAnyServerCertificateValidator,
|
||||||
|
};
|
||||||
|
using var httpClient = new HttpClient(handler);
|
||||||
|
using var response = await httpClient.GetAsync(metadataAddress);
|
||||||
|
var content = await response.Content.ReadAsStringAsync();
|
||||||
|
var preview = content.Length > 500 ? content[..500] : content;
|
||||||
|
|
||||||
|
logger.Info(
|
||||||
|
"Diagnostic Keycloak metadata | Url: {MetadataAddress} | Status: {StatusCode} | ContentType: {ContentType} | Body: {BodyPreview}",
|
||||||
|
metadataAddress,
|
||||||
|
(int)response.StatusCode,
|
||||||
|
response.Content.Headers.ContentType?.ToString(),
|
||||||
|
preview.Replace(Environment.NewLine, " "));
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
logger.Error(exception, "Diagnostic Keycloak metadata impossible | Url: {MetadataAddress} | Message: {Message}", metadataAddress, exception.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
@@ -324,6 +366,7 @@ try
|
|||||||
builder.Services.AddResponseCompression();
|
builder.Services.AddResponseCompression();
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
await LogKeycloakMetadataAsync(builder.Configuration, logger);
|
||||||
|
|
||||||
// Très important avant tout middleware qui lit le scheme/host de la requête.
|
// Très important avant tout middleware qui lit le scheme/host de la requête.
|
||||||
app.UseForwardedHeaders();
|
app.UseForwardedHeaders();
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
},
|
},
|
||||||
"Keycloak": {
|
"Keycloak": {
|
||||||
"Authority": "https://10.4.0.131/keycloak/realms/webzine-realm",
|
"Authority": "https://10.4.0.131/keycloak/realms/webzine-realm",
|
||||||
"MetadataAddress": "http://10.4.0.131/keycloak/realms/webzine-realm/.well-known/openid-configuration",
|
"MetadataAddress": "https://10.4.0.131/keycloak/realms/webzine-realm/.well-known/openid-configuration",
|
||||||
"PublicOrigin": "http://192.168.10.80:8080"
|
"PublicOrigin": "http://192.168.10.80:8080"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user