Правка настроек Keycloak в appsettings.json

This commit is contained in:
Оля Бизюкова 2024-12-17 10:58:30 +05:00
parent 441d529373
commit 218eb65201
3 changed files with 14 additions and 14 deletions

View File

@ -74,16 +74,16 @@ public static class DependencyInjection
private static void AddKeyCloakAuthentication(this IServiceCollection services, IConfiguration configuration) private static void AddKeyCloakAuthentication(this IServiceCollection services, IConfiguration configuration)
{ {
var keyCloakHost = configuration["Authentication:Audience"]; var keyCloakHost = configuration["KeyCloakAuthentication:Host"];
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options => .AddJwtBearer(options =>
{ {
options.RequireHttpsMetadata = false; options.RequireHttpsMetadata = false;
options.Audience = configuration["Authentication:Audience"]; options.Audience = configuration["KeyCloakAuthentication:Audience"];
options.MetadataAddress = $"{keyCloakHost}/.well-known/openid-configuration"; options.MetadataAddress = $"{keyCloakHost}/.well-known/openid-configuration";
options.TokenValidationParameters = new TokenValidationParameters options.TokenValidationParameters = new TokenValidationParameters
{ {
ValidIssuer = keyCloakHost, ValidIssuer = keyCloakHost
}; };
}); });
} }
@ -144,6 +144,8 @@ public static class DependencyInjection
#region Keycloak #region Keycloak
private static void AddKeycloakSecurity(this SwaggerGenOptions options, IConfiguration configuration) private static void AddKeycloakSecurity(this SwaggerGenOptions options, IConfiguration configuration)
{ {
var keyCloakHost = configuration["KeyCloakAuthentication:Host"];
options.AddSecurityDefinition("Keycloak", new OpenApiSecurityScheme options.AddSecurityDefinition("Keycloak", new OpenApiSecurityScheme
{ {
Description = @"JWT Authorization header using the Bearer scheme. Enter 'Bearer' [space] and then your token in the text input below. Example: 'Bearer 12345token'", Description = @"JWT Authorization header using the Bearer scheme. Enter 'Bearer' [space] and then your token in the text input below. Example: 'Bearer 12345token'",
@ -154,7 +156,7 @@ public static class DependencyInjection
{ {
Implicit = new OpenApiOAuthFlow Implicit = new OpenApiOAuthFlow
{ {
AuthorizationUrl = new Uri(configuration["Authentication:AuthorizationUrl"]!), AuthorizationUrl = new Uri($"{keyCloakHost}/protocol/openid-connect/auth"),
} }
} }
}); });

View File

@ -9,12 +9,11 @@
"DefaultConnection": "Host=localhost;Database=persistence;Username=postgres;Password=q;Persist Security Info=True" "DefaultConnection": "Host=localhost;Database=persistence;Username=postgres;Password=q;Persist Security Info=True"
}, },
"AllowedHosts": "*", "AllowedHosts": "*",
"Authentication": {
"Audience": "account",
"ValidIssuer": "http://192.168.0.10:8321/realms/Persistence",
"AuthorizationUrl": "http://192.168.0.10:8321/realms/Persistence/protocol/openid-connect/auth"
},
"NeedUseKeyCloak": false, "NeedUseKeyCloak": false,
"KeyCloakAuthentication": {
"Audience": "account",
"Host": "http://192.168.0.10:8321/realms/Persistence"
},
"AuthUser": { "AuthUser": {
"username": "myuser", "username": "myuser",
"password": 12345, "password": 12345,

View File

@ -9,12 +9,11 @@
"DefaultConnection": "Host=localhost;Database=persistence;Username=postgres;Password=q;Persist Security Info=True" "DefaultConnection": "Host=localhost;Database=persistence;Username=postgres;Password=q;Persist Security Info=True"
}, },
"AllowedHosts": "*", "AllowedHosts": "*",
"Authentication": {
"Audience": "account",
"ValidIssuer": "http://192.168.0.10:8321/realms/Persistence",
"AuthorizationUrl": "http://192.168.0.10:8321/realms/Persistence/protocol/openid-connect/auth"
},
"NeedUseKeyCloak": false, "NeedUseKeyCloak": false,
"KeyCloakAuthentication": {
"Audience": "account",
"Host": "http://192.168.0.10:8321/realms/Persistence"
},
"AuthUser": { "AuthUser": {
"username": "myuser", "username": "myuser",
"password": 12345, "password": 12345,