@@ -2,6 +2,7 @@ import { IncomingMessage } from "node:http";
2
2
import { logger } from "../../core/Logger.js" ;
3
3
import { AuthProvider , AuthResult , DEFAULT_AUTH_ERROR } from "../types.js" ;
4
4
5
+ export const DEFAULT_API_KEY_HEADER_NAME = "X-API-Key"
5
6
/**
6
7
* Configuration options for API key authentication
7
8
*/
@@ -26,7 +27,7 @@ export class APIKeyAuthProvider implements AuthProvider {
26
27
27
28
constructor ( config : APIKeyConfig ) {
28
29
this . config = {
29
- headerName : "X-API-Key" ,
30
+ headerName : DEFAULT_API_KEY_HEADER_NAME ,
30
31
...config
31
32
} ;
32
33
@@ -78,24 +79,21 @@ export class APIKeyAuthProvider implements AuthProvider {
78
79
}
79
80
80
81
if ( ! apiKey ) {
81
- logger . debug ( `API Key header missing. Checked variations: ${ headerVariations . join ( ', ' ) } ` ) ;
82
+ logger . debug ( `API Key header missing}` ) ;
82
83
logger . debug ( `Available headers: ${ Object . keys ( req . headers ) . join ( ', ' ) } ` ) ;
83
84
return false ;
84
85
}
85
86
86
87
logger . debug ( `Found API key in header: ${ matchedHeader } ` ) ;
87
- logger . debug ( `Comparing provided key: ${ apiKey . substring ( 0 , 3 ) } ... with ${ this . config . keys . length } configured keys` ) ;
88
88
89
89
for ( const validKey of this . config . keys ) {
90
- logger . debug ( `Comparing with key: ${ validKey . substring ( 0 , 3 ) } ...` ) ;
91
90
if ( apiKey === validKey ) {
92
- logger . debug ( `API Key authentication successful - matched key starting with ${ validKey . substring ( 0 , 3 ) } ... ` ) ;
91
+ logger . debug ( `API Key authentication successful` ) ;
93
92
return true ;
94
93
}
95
94
}
96
95
97
- logger . debug ( `Invalid API Key provided: ${ apiKey . substring ( 0 , 3 ) } ...` ) ;
98
- logger . debug ( `Expected one of: ${ this . config . keys . map ( k => k . substring ( 0 , 3 ) + '...' ) . join ( ', ' ) } ` ) ;
96
+ logger . debug ( `Invalid API Key provided` ) ;
99
97
return false ;
100
98
}
101
99
0 commit comments