@@ -35,9 +35,13 @@ public static AuthenticationBuilder AddSimpleAuthentication(this IServiceCollect
3535 {
3636 ArgumentNullException . ThrowIfNull ( services ) ;
3737 ArgumentNullException . ThrowIfNull ( configuration ) ;
38- ArgumentNullException . ThrowIfNull ( sectionName ) ;
38+ ArgumentException . ThrowIfNullOrWhiteSpace ( sectionName ) ;
3939
40- var defaultAuthenticationScheme = configuration . GetValue < string > ( $ "{ sectionName } :DefaultScheme") ;
40+ var defaultAuthenticationScheme = configuration . GetValue < string ? > ( $ "{ sectionName } :DefaultScheme") ;
41+ if ( string . IsNullOrWhiteSpace ( defaultAuthenticationScheme ) )
42+ {
43+ defaultAuthenticationScheme = null ; // treat empty/whitespace as no value.
44+ }
4145
4246 var builder = services . AddAuthentication ( options =>
4347 {
@@ -65,7 +69,7 @@ public static AuthenticationBuilder AddSimpleAuthentication(this AuthenticationB
6569 {
6670 ArgumentNullException . ThrowIfNull ( builder ) ;
6771 ArgumentNullException . ThrowIfNull ( configuration ) ;
68- ArgumentNullException . ThrowIfNull ( sectionName ) ;
72+ ArgumentException . ThrowIfNullOrWhiteSpace ( sectionName ) ;
6973
7074 if ( addAuthorizationServices )
7175 {
@@ -86,11 +90,11 @@ static void CheckAddJwtBearer(AuthenticationBuilder builder, IConfigurationSecti
8690 return ;
8791 }
8892
89- ArgumentNullException . ThrowIfNull ( settings . SchemeName , nameof ( JwtBearerSettings . SchemeName ) ) ;
90- ArgumentNullException . ThrowIfNull ( settings . SecurityKey , nameof ( JwtBearerSettings . SecurityKey ) ) ;
91- ArgumentNullException . ThrowIfNull ( settings . Algorithm , nameof ( JwtBearerSettings . Algorithm ) ) ;
92- ArgumentNullException . ThrowIfNull ( settings . NameClaimType , nameof ( JwtBearerSettings . NameClaimType ) ) ;
93- ArgumentNullException . ThrowIfNull ( settings . RoleClaimType , nameof ( JwtBearerSettings . RoleClaimType ) ) ;
93+ ArgumentException . ThrowIfNullOrWhiteSpace ( settings . SchemeName , nameof ( JwtBearerSettings . SchemeName ) ) ;
94+ ArgumentException . ThrowIfNullOrWhiteSpace ( settings . SecurityKey , nameof ( JwtBearerSettings . SecurityKey ) ) ;
95+ ArgumentException . ThrowIfNullOrWhiteSpace ( settings . Algorithm , nameof ( JwtBearerSettings . Algorithm ) ) ;
96+ ArgumentException . ThrowIfNullOrWhiteSpace ( settings . NameClaimType , nameof ( JwtBearerSettings . NameClaimType ) ) ;
97+ ArgumentException . ThrowIfNullOrWhiteSpace ( settings . RoleClaimType , nameof ( JwtBearerSettings . RoleClaimType ) ) ;
9498
9599 builder . Services . Configure < JwtBearerSettings > ( section ) ;
96100
@@ -124,9 +128,9 @@ static void CheckAddApiKey(AuthenticationBuilder builder, IConfigurationSection
124128 return ;
125129 }
126130
127- ArgumentNullException . ThrowIfNull ( settings . SchemeName , nameof ( ApiKeySettings . SchemeName ) ) ;
128- ArgumentNullException . ThrowIfNull ( settings . NameClaimType , nameof ( JwtBearerSettings . NameClaimType ) ) ;
129- ArgumentNullException . ThrowIfNull ( settings . RoleClaimType , nameof ( JwtBearerSettings . RoleClaimType ) ) ;
131+ ArgumentException . ThrowIfNullOrWhiteSpace ( settings . SchemeName , nameof ( ApiKeySettings . SchemeName ) ) ;
132+ ArgumentException . ThrowIfNullOrWhiteSpace ( settings . NameClaimType , nameof ( JwtBearerSettings . NameClaimType ) ) ;
133+ ArgumentException . ThrowIfNullOrWhiteSpace ( settings . RoleClaimType , nameof ( JwtBearerSettings . RoleClaimType ) ) ;
130134
131135 if ( string . IsNullOrWhiteSpace ( settings . HeaderName ) && string . IsNullOrWhiteSpace ( settings . QueryStringKey ) )
132136 {
@@ -135,7 +139,7 @@ static void CheckAddApiKey(AuthenticationBuilder builder, IConfigurationSection
135139
136140 if ( ! string . IsNullOrWhiteSpace ( settings . ApiKeyValue ) )
137141 {
138- ArgumentNullException . ThrowIfNull ( settings . UserName , nameof ( ApiKeySettings . UserName ) ) ;
142+ ArgumentException . ThrowIfNullOrWhiteSpace ( settings . UserName , nameof ( ApiKeySettings . UserName ) ) ;
139143 }
140144
141145 if ( settings . ApiKeys . Any ( k => string . IsNullOrWhiteSpace ( k . Value ) || string . IsNullOrWhiteSpace ( k . UserName ) ) )
@@ -167,18 +171,18 @@ static void CheckAddBasicAuthentication(AuthenticationBuilder builder, IConfigur
167171 return ;
168172 }
169173
170- ArgumentNullException . ThrowIfNull ( settings . SchemeName , nameof ( BasicAuthenticationSettings . SchemeName ) ) ;
171- ArgumentNullException . ThrowIfNull ( settings . NameClaimType , nameof ( JwtBearerSettings . NameClaimType ) ) ;
172- ArgumentNullException . ThrowIfNull ( settings . RoleClaimType , nameof ( JwtBearerSettings . RoleClaimType ) ) ;
174+ ArgumentException . ThrowIfNullOrWhiteSpace ( settings . SchemeName , nameof ( BasicAuthenticationSettings . SchemeName ) ) ;
175+ ArgumentException . ThrowIfNullOrWhiteSpace ( settings . NameClaimType , nameof ( JwtBearerSettings . NameClaimType ) ) ;
176+ ArgumentException . ThrowIfNullOrWhiteSpace ( settings . RoleClaimType , nameof ( JwtBearerSettings . RoleClaimType ) ) ;
173177
174178 if ( ! string . IsNullOrWhiteSpace ( settings . UserName ) )
175179 {
176- ArgumentNullException . ThrowIfNull ( settings . Password , nameof ( BasicAuthenticationSettings . Password ) ) ;
180+ ArgumentException . ThrowIfNullOrWhiteSpace ( settings . Password , nameof ( BasicAuthenticationSettings . Password ) ) ;
177181 }
178182
179183 if ( ! string . IsNullOrWhiteSpace ( settings . Password ) )
180184 {
181- ArgumentNullException . ThrowIfNull ( settings . UserName , nameof ( BasicAuthenticationSettings . UserName ) ) ;
185+ ArgumentException . ThrowIfNullOrWhiteSpace ( settings . UserName , nameof ( BasicAuthenticationSettings . UserName ) ) ;
182186 }
183187
184188 if ( settings . Credentials . Any ( c => string . IsNullOrWhiteSpace ( c . UserName ) || string . IsNullOrWhiteSpace ( c . Password ) ) )
0 commit comments