Path: redb/redb.Templates/templates/redb-identity-app/RedbIdentityApp.Module/ModuleSettings.cs Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Templates/templates/redb-identity-app/RedbIdentityApp.Module/ModuleSettings.cs ---- using System.Globalization; using redb.Route.Abstractions; namespace RedbIdentityApp.Module; /// /// The module's settings, read from the properties of its route context. The Tsak worker fills them from /// RedbIdentityApp.Module.config.json, then from the Tsak:Contexts:{context}:Override section of /// its configuration, which wins. The three client secrets belong only in the Override layer /// (environment variables, deploy/.env), never in the module's config file. /// public sealed record ModuleSettings( string ApiHost, int ApiPort, string ResourceClientId, string ResourceClientSecret, string ApiScope, string AdminScope, string ManagementClientId, string ManagementClientSecret, string? WebClientId, string? WebClientSecret, IReadOnlyList WebRedirectUris, IReadOnlyList WebPostLogoutRedirectUris, TimeSpan IntrospectionCacheTtl, TimeSpan InactiveCacheTtl, TimeSpan IntrospectionTimeout) { /// The direct-vm address Identity's audit sends its events to; see README, "Revocation". public string EventsEndpoint(IRouteContext context) => $"direct-vm://{context.ContextId}-identity-events"; public static ModuleSettings FromContext(IRouteContext context) { var api = Section(context, context.GetProperty>("Api"), "Api"); var identity = Section(context, context.GetProperty>("Identity"), "Identity"); var introspection = identity.TryGetValue("Introspection", out var raw) && raw is IDictionary section ? section : new Dictionary(); var webClientId = Optional(identity, "WebClientId"); return new( // 127.0.0.1 by default: the web server shares the worker's network namespace. ApiHost: Required(context, api, "Api", "Host"), ApiPort: int.Parse(Required(context, api, "Api", "Port"), CultureInfo.InvariantCulture), ResourceClientId: Required(context, identity, "Identity", "ResourceClientId"), ResourceClientSecret: Secret(context, identity, "ResourceClientSecret"), ApiScope: Required(context, identity, "Identity", "ApiScope"), AdminScope: Required(context, identity, "Identity", "AdminScope"), ManagementClientId: Required(context, identity, "Identity", "ManagementClientId"), ManagementClientSecret: Secret(context, identity, "ManagementClientSecret"), WebClientId: webClientId, WebClientSecret: webClientId is null ? null : Secret(context, identity, "WebClientSecret"), WebRedirectUris: List(identity, "WebRedirectUris"), WebPostLogoutRedirectUris: List(identity, "WebPostLogoutRedirectUris"), IntrospectionCacheTtl: Seconds(introspection, "CacheSeconds", 60), InactiveCacheTtl: Seconds(introspection, "InactiveCacheSeconds", 10), IntrospectionTimeout: Seconds(introspection, "TimeoutSeconds", 5)); } private static IDictionary Section(IRouteContext context, IDictionary? section, string name) => section ?? throw new InvalidOperationException( $"{name} is not configured for context '{context.ContextId}': see RedbIdentityApp.Module.config.json."); private static string? Optional(IDictionary section, string key) => section.TryGetValue(key, out var value) && Convert.ToString(value, CultureInfo.InvariantCulture) is { Length: > 0 } text ? text.Trim() : null; private static string Required(IRouteContext context, IDictionary section, string sectionName, string key) => Optional(section, key) ?? throw new InvalidOperationException( $"{sectionName}:{key} is not configured for context '{context.ContextId}': set it in " + $"RedbIdentityApp.Module.config.json or in Tsak:Contexts:{context.ContextId}:Override."); // A client secret: only from the environment, and long enough not to be guessed. private static string Secret(IRouteContext context, IDictionary section, string key) { var value = Optional(section, key) ?? throw new InvalidOperationException( $"Identity:{key} is not set for context '{context.ContextId}': set " + $"Tsak__Contexts__{context.ContextId}__Override__Identity__{key} in the worker's environment."); return value.Length >= 32 ? value : throw new InvalidOperationException($"Identity:{key} of context '{context.ContextId}' must be at least 32 characters."); } // A list is written as one string, items separated by commas or spaces: the same text works in the // config file and in one environment variable. private static IReadOnlyList List(IDictionary section, string key) => Optional(section, key)?.Split([',', ' ', ';'], StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries) ?? []; private static TimeSpan Seconds(IDictionary section, string key, int fallback) => TimeSpan.FromSeconds(Optional(section, key) is { } text ? int.Parse(text, CultureInfo.InvariantCulture) : fallback); }