Skip to content

Commit bda24b2

Browse files
committed
fix(api-gateway): support proxy when fetching jwk for token validation
When fetching the JWK data needed to validate the auth token, the environment proxy settings are not honored.
1 parent 0bd4866 commit bda24b2

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

packages/cubejs-api-gateway/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"moment-timezone": "^0.5.27",
4646
"nexus": "^1.1.0",
4747
"node-fetch": "^2.6.1",
48+
"proxy-agent": "^6.4.0",
4849
"ramda": "^0.27.0",
4950
"uuid": "^8.3.2"
5051
},

packages/cubejs-api-gateway/src/jwk.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import crypto from 'crypto';
33
import { asyncMemoizeBackground, asyncRetry, BackgroundMemoizeOptions } from '@cubejs-backend/shared';
44
import fetch from 'node-fetch';
55
import jwkToPem from 'jwk-to-pem';
6+
import { ProxyAgent } from 'proxy-agent';
67
import { JWTOptions } from './interfaces';
78

89
const HEADER_REGEXP = /([a-zA-Z][a-zA-Z_-]*)\s*(?:=(?:"([^"]*)"|([^ \t",;]*)))?/g;
@@ -51,7 +52,7 @@ export type JWKsFetcherOptions = Pick<BackgroundMemoizeOptions<any, any>, 'onBac
5152

5253
export const createJWKsFetcher = (jwtOptions: JWTOptions, options: JWKsFetcherOptions) => {
5354
const fetchJwkUrl = asyncMemoizeBackground(async (url: string) => {
54-
const response = await asyncRetry(() => fetch(url), {
55+
const response = await asyncRetry(() => fetch(url, { agent: new ProxyAgent() }), {
5556
times: jwtOptions.jwkRetry || 3,
5657
});
5758
const json = await response.json();

0 commit comments

Comments
 (0)