@@ -9,6 +9,16 @@ import EnvoyPluginJobAttachment from './EnvoyPluginJobAttachment';
99import EnvoyPluginSDK from './EnvoyPluginSDK' ;
1010import EnvoyPluginAPI from './EnvoyPluginAPI' ;
1111
12+ /**
13+ * Options for configuring the Envoy middleware.
14+ */
15+ export interface EnvoyMiddlewareOptions extends EnvoySignatureVerifierOptions {
16+ /** Optional custom client ID to use for API authentication instead of environment variable */
17+ customClientId ?: string ;
18+ /** Optional custom client secret to use for API authentication instead of environment variable */
19+ customClientSecret ?: string ;
20+ }
21+
1222/**
1323 * Sets up an {@link EnvoyPluginSDK} object in the path `req.envoy`.
1424 * Modifies the `res` object to include Envoy's helpers, per {@link EnvoyResponse}.
@@ -18,7 +28,7 @@ import EnvoyPluginAPI from './EnvoyPluginAPI';
1828 *
1929 * @category Middleware
2030 */
21- export function envoyMiddleware ( options ?: EnvoySignatureVerifierOptions ) : RequestHandler {
31+ export function envoyMiddleware ( options ?: EnvoyMiddlewareOptions ) : RequestHandler {
2232 const signatureVerifier = new EnvoySignatureVerifier ( options ) ;
2333 const verify = ( req : VerifiedRequest , res : Response , rawBody : Buffer ) => {
2434 req [ VERIFIED ] = signatureVerifier . verify ( req , rawBody ) ;
@@ -35,7 +45,10 @@ export function envoyMiddleware(options?: EnvoySignatureVerifierOptions): Reques
3545 try {
3646 const now = Date . now ( ) ;
3747 if ( now > threshold ) {
38- const { access_token : rawAccessToken , expires_in : expiresIn } = await EnvoyPluginAPI . loginAsPlugin ( ) ;
48+ const hasCustomCredentials = options ?. customClientId && options ?. customClientSecret ;
49+ const { access_token : rawAccessToken , expires_in : expiresIn } = hasCustomCredentials
50+ ? await EnvoyPluginAPI . loginAsPlugin ( options ?. customClientId , options ?. customClientSecret )
51+ : await EnvoyPluginAPI . loginAsPlugin ( ) ;
3952 accessToken = rawAccessToken ;
4053 threshold = now + expiresIn * 1000 - 1000 * 60 * 10 ;
4154 }
0 commit comments