@@ -19,6 +19,8 @@ public class IdentityHostingStartup : IHostingStartup
1919{
2020 private const string AuthClientIdKey = "XtremeIdiots:Auth:ClientId" ;
2121 private const string AuthClientSecretKey = "XtremeIdiots:Auth:ClientSecret" ;
22+ private const string AppConfigNamespacePrefix = "XtremeIdiots.Portal.Web:" ;
23+ private const string SqlConnectionStringKey = "sql_connection_string" ;
2224
2325 private const int SecurityStampValidationIntervalMinutes = 15 ;
2426 private const int CookieExpirationDays = 7 ;
@@ -45,12 +47,12 @@ private static void ValidateConfiguration(IConfiguration configuration)
4547 {
4648 AuthClientIdKey ,
4749 AuthClientSecretKey ,
48- "sql_connection_string"
50+ SqlConnectionStringKey
4951 } ;
5052
5153 foreach ( var key in requiredKeys )
5254 {
53- if ( string . IsNullOrEmpty ( configuration [ key ] ) )
55+ if ( string . IsNullOrEmpty ( GetConfigurationValue ( configuration , key ) ) )
5456 {
5557 throw new InvalidOperationException ( $ "Required configuration key '{ key } ' is missing or empty") ;
5658 }
@@ -60,7 +62,7 @@ private static void ValidateConfiguration(IConfiguration configuration)
6062 private static void ConfigureDatabase ( IServiceCollection services , IConfiguration configuration )
6163 {
6264 services . AddDbContext < IdentityDataContext > ( options =>
63- options . UseSqlServer ( configuration [ "sql_connection_string" ] ) ) ;
65+ options . UseSqlServer ( GetConfigurationValue ( configuration , SqlConnectionStringKey ) ) ) ;
6466 }
6567
6668 private static void ConfigureIdentity ( IServiceCollection services )
@@ -106,8 +108,8 @@ private static void ConfigureAuthentication(IServiceCollection services, IConfig
106108 } )
107109 . AddOAuth ( OAuthSchemeName , options =>
108110 {
109- options . ClientId = configuration [ AuthClientIdKey ] ?? throw new InvalidOperationException ( "OAuth client ID is required" ) ;
110- options . ClientSecret = configuration [ AuthClientSecretKey ] ?? throw new InvalidOperationException ( "OAuth client secret is required" ) ;
111+ options . ClientId = GetConfigurationValue ( configuration , AuthClientIdKey ) ?? throw new InvalidOperationException ( "OAuth client ID is required" ) ;
112+ options . ClientSecret = GetConfigurationValue ( configuration , AuthClientSecretKey ) ?? throw new InvalidOperationException ( "OAuth client secret is required" ) ;
111113
112114 options . CallbackPath = new PathString ( "/signin-xtremeidiots" ) ;
113115
@@ -158,4 +160,9 @@ private static void ConfigureDataProtection(IServiceCollection services)
158160 . SetApplicationName ( ApplicationName )
159161 . PersistKeysToDbContext < IdentityDataContext > ( ) ;
160162 }
163+
164+ private static string ? GetConfigurationValue ( IConfiguration configuration , string key )
165+ {
166+ return configuration [ key ] ?? configuration [ $ "{ AppConfigNamespacePrefix } { key } "] ;
167+ }
161168}
0 commit comments