Skip to content

Commit c739f7f

Browse files
committed
feat: add optional params to middleware for client id and secret
1 parent 4f0539b commit c739f7f

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@envoy/envoy-integrations-sdk",
3-
"version": "2.3.6",
3+
"version": "2.4.0-beta.1",
44
"description": "SDK for building Envoy integrations.",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/sdk/middleware.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ import EnvoyPluginJobAttachment from './EnvoyPluginJobAttachment';
99
import EnvoyPluginSDK from './EnvoyPluginSDK';
1010
import 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

Comments
 (0)