@@ -64,7 +64,6 @@ public sealed class CrudApiAction
6464{
6565 [ System . Text . Json . Serialization . JsonConverter ( typeof ( JsonStringEnumConverter ) ) ]
6666 public CrudApiActionType Action { get ; set ; } = CrudApiActionType . GetAll ;
67- public CrudApiApiKeyAuth ? ApiKeyAuthConfig { get ; set ; }
6867 [ System . Text . Json . Serialization . JsonConverter ( typeof ( JsonStringEnumConverter ) ) ]
6968 public CrudApiAuthType Auth { get ; set ; } = CrudApiAuthType . None ;
7069 public CrudApiEntraAuth ? EntraAuthConfig { get ; set ; }
@@ -140,26 +139,6 @@ Configuration.ApiKeyAuthConfig is not null &&
140139 Configuration . Auth = CrudApiAuthType . None ;
141140 }
142141
143- foreach ( var action in Configuration . Actions )
144- {
145- if ( action . Auth == CrudApiAuthType . ApiKey &&
146- action . ApiKeyAuthConfig is null &&
147- Configuration . ApiKeyAuthConfig is null )
148- {
149- Logger . LogError ( "API Key auth is enabled for action {Action} but no configuration is provided. Action will work anonymously." , action . Action ) ;
150- action . Auth = CrudApiAuthType . None ;
151- }
152-
153- var effectiveApiKeyConfig = action . ApiKeyAuthConfig ?? Configuration . ApiKeyAuthConfig ;
154- if ( action . Auth == CrudApiAuthType . ApiKey &&
155- effectiveApiKeyConfig is not null &&
156- string . IsNullOrEmpty ( effectiveApiKeyConfig . ApiKey ) )
157- {
158- Logger . LogError ( "API Key auth is enabled for action {Action} but no API key is configured. Action will work anonymously." , action . Action ) ;
159- action . Auth = CrudApiAuthType . None ;
160- }
161- }
162-
163142 if ( ! ProxyUtils . MatchesUrlToWatch ( UrlsToWatch , Configuration . BaseUrl , true ) )
164143 {
165144 Logger . LogWarning (
@@ -344,22 +323,12 @@ private void AddCORSHeaders(Request request, List<HttpHeader> headers)
344323 allowHeaders . Add ( "authorization" ) ;
345324 }
346325
347- if ( Configuration . ApiKeyAuthConfig is not null ||
348- Configuration . Actions . Any ( a => a . Auth == CrudApiAuthType . ApiKey ) )
326+ if ( Configuration . ApiKeyAuthConfig is not null &&
327+ ! string . IsNullOrEmpty ( Configuration . ApiKeyAuthConfig . HeaderName ) )
349328 {
350- var apiKeyHeaders = new List < string ? > { Configuration . ApiKeyAuthConfig ? . HeaderName }
351- . Concat ( Configuration . Actions
352- . Where ( a => a . ApiKeyAuthConfig is not null )
353- . Select ( a => a . ApiKeyAuthConfig ! . HeaderName ) )
354- . Where ( h => ! string . IsNullOrEmpty ( h ) )
355- . Distinct ( StringComparer . OrdinalIgnoreCase ) ;
356-
357- foreach ( var apiKeyHeader in apiKeyHeaders )
329+ if ( ! allowHeaders . Contains ( Configuration . ApiKeyAuthConfig . HeaderName , StringComparer . OrdinalIgnoreCase ) )
358330 {
359- if ( ! allowHeaders . Contains ( apiKeyHeader ! , StringComparer . OrdinalIgnoreCase ) )
360- {
361- allowHeaders . Add ( apiKeyHeader ! ) ;
362- }
331+ allowHeaders . Add ( Configuration . ApiKeyAuthConfig . HeaderName ) ;
363332 }
364333 }
365334
@@ -388,15 +357,15 @@ private bool AuthorizeRequest(ProxyRequestArgs e, CrudApiAction? action = null)
388357
389358 if ( authType == CrudApiAuthType . ApiKey )
390359 {
391- return AuthorizeApiKeyRequest ( e , action ) ;
360+ return AuthorizeApiKeyRequest ( e ) ;
392361 }
393362
394363 return AuthorizeEntraRequest ( e , action ) ;
395364 }
396365
397- private bool AuthorizeApiKeyRequest ( ProxyRequestArgs e , CrudApiAction ? action = null )
366+ private bool AuthorizeApiKeyRequest ( ProxyRequestArgs e )
398367 {
399- var apiKeyAuthConfig = action ? . ApiKeyAuthConfig ?? Configuration . ApiKeyAuthConfig ;
368+ var apiKeyAuthConfig = Configuration . ApiKeyAuthConfig ;
400369
401370 Debug . Assert ( apiKeyAuthConfig is not null , "ApiKeyAuthConfig is null when API key auth is required." ) ;
402371
0 commit comments