diff --git a/README.md b/README.md index fb4894a..b38df2f 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,10 @@ This is the sample of using the server in `docker-compose` configuration: "ShowKeySet": true } } + ACCOUNT_OPTIONS_INLINE: | + { + "AutomaticRedirectAfterSignOut": true + } API_SCOPES_INLINE: | [ { @@ -130,6 +134,7 @@ Clients configuration should be provided. Test user configuration is optional (u There are two ways to provide configuration for supported scopes, clients and users. You can either provide it inline as environment variable: * `SERVER_OPTIONS_INLINE` +* `ACCOUNT_OPTIONS_INLINE` * `API_SCOPES_INLINE` * `USERS_CONFIGURATION_INLINE` * `CLIENTS_CONFIGURATION_INLINE` @@ -139,6 +144,7 @@ There are two ways to provide configuration for supported scopes, clients and us or mount volume and provide the path to configuration json as environment variable: * `SERVER_OPTIONS_PATH` +* `ACCOUNT_OPTIONS_PATH` * `API_SCOPES_PATH` * `USERS_CONFIGURATION_PATH` * `CLIENTS_CONFIGURATION_PATH` diff --git a/e2e/config/account-options.json b/e2e/config/account-options.json new file mode 100644 index 0000000..3eb27a6 --- /dev/null +++ b/e2e/config/account-options.json @@ -0,0 +1,3 @@ +{ + "AutomaticRedirectAfterSignOut": true +} diff --git a/e2e/docker-compose.yml b/e2e/docker-compose.yml index 92a304e..052de71 100644 --- a/e2e/docker-compose.yml +++ b/e2e/docker-compose.yml @@ -10,6 +10,7 @@ services: ASPNETCORE_Kestrel__Certificates__Default__Password: oidc-server-mock-pwd ASPNETCORE_Kestrel__Certificates__Default__Path: /https/aspnetapp.pfx SERVER_OPTIONS_PATH: /config/server-options.json + ACCOUNT_OPTIONS_PATH: /config/account-options.json API_SCOPES_PATH: /config/api-scopes.json API_RESOURCES_PATH: /config/api-resources.json USERS_CONFIGURATION_PATH: /config/user-configuration.json diff --git a/src/Config.cs b/src/Config.cs index ff58cc3..94bf41c 100644 --- a/src/Config.cs +++ b/src/Config.cs @@ -44,6 +44,21 @@ public static IdentityServerOptions GetServerOptions() return serverOptions; } + public static void ConfigureAccountOptions() + { + string accountOptionsStr = Environment.GetEnvironmentVariable("ACCOUNT_OPTIONS_INLINE"); + if (string.IsNullOrWhiteSpace(accountOptionsStr)) + { + var accountOptionsFilePath = Environment.GetEnvironmentVariable("ACCOUNT_OPTIONS_PATH"); + if (string.IsNullOrWhiteSpace(accountOptionsFilePath)) + { + return; + } + accountOptionsStr = File.ReadAllText(accountOptionsFilePath); + } + AccountOptionsHelper.ConfigureAccountOptions(accountOptionsStr); + } + public static IEnumerable GetServerCorsAllowedOrigins() { string allowedOriginsStr = Environment.GetEnvironmentVariable("SERVER_CORS_ALLOWED_ORIGINS_INLINE"); diff --git a/src/Helpers/AccountOptionsHelper.cs b/src/Helpers/AccountOptionsHelper.cs new file mode 100644 index 0000000..7114d9e --- /dev/null +++ b/src/Helpers/AccountOptionsHelper.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using Serilog; + +namespace OpenIdConnectServer.Helpers +{ + public class AccountOptionsHelper + { + public static void ConfigureAccountOptions(string accountOptionsStr) + { + var accountOptions = JsonConvert.DeserializeObject(accountOptionsStr); + var targetFields = typeof(IdentityServerHost.Quickstart.UI.AccountOptions).GetFields(); + var jValueValueProp = typeof(JValue).GetProperty(nameof(JValue.Value)); + Array.ForEach(targetFields, k => { + if (accountOptions.ContainsKey(k.Name)) { + var fieldJValue = accountOptions[k.Name] as JValue; + var fieldValue = jValueValueProp.GetValue(fieldJValue); + k.SetValue(null, fieldValue); + } + }); + } + } +} \ No newline at end of file diff --git a/src/Startup.cs b/src/Startup.cs index 2bf4b42..15d647f 100644 --- a/src/Startup.cs +++ b/src/Startup.cs @@ -33,6 +33,8 @@ public void ConfigureServices(IServiceCollection services) var aspNetServicesOptions = Config.GetAspNetServicesOptions(); AspNetServicesHelper.ConfigureAspNetServices(services, aspNetServicesOptions); + Config.ConfigureAccountOptions(); + services.AddRouting(); }