Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use requestAgentOptions with ExpressJwtOptions / Typescript #167

Closed
mbs99 opened this issue Aug 24, 2020 · 4 comments · Fixed by #206
Closed

use requestAgentOptions with ExpressJwtOptions / Typescript #167

mbs99 opened this issue Aug 24, 2020 · 4 comments · Fixed by #206

Comments

@mbs99
Copy link

mbs99 commented Aug 24, 2020

We're using version 1.9.0 with express and express-jwt

interface ClientOptions {
    jwksUri: string;
    rateLimit?: boolean;
    cache?: boolean;
    cacheMaxEntries?: number;
    cacheMaxAge?: number;
    jwksRequestsPerMinute?: number;
    proxy?: string;
    strictSsl?: boolean;
    requestHeaders?: Headers;
    timeout?: number;
  }
``` doens't include requestAgentOptions for configuring https certs. Can this be added?
@mbs99 mbs99 changed the title use requestAgentOptions with ExpressJwtOptions use requestAgentOptions with ExpressJwtOptions / Typescript Aug 24, 2020
@jarvisuser90
Copy link

I'm running into the same problem. We need this option so we can set our custom CA.

@jarvisuser90
Copy link

FYI: This is my workaround for the problem.

// TODO: Temporary fix until "node-jwks-rsa" project adds native support for the requestAgentOptions property.
// Extend ExpressJwtOptions interface.
// Must extend BEFORE we use jwksRsa.expressJwtSecret.
declare module "jwks-rsa" {
  interface ExpressJwtOptions {
    requestAgentOptions?: AgentOptions;
  }
}

jwt({
  // Dynamically provide signing keys 
  // provided by the JWKS endpoint.
  secret: jwksRsa.expressJwtSecret({
    strictSsl: true,
    requestAgentOptions: {
      ca: fs.readFileSync(path.resolve(__dirname, "ca.crt"), "utf8")
    },
    cache: config.get("jwt.cache") as boolean,
    rateLimit: config.get("jwt.rateLimit") as boolean,
    jwksRequestsPerMinute: config.get("jwt.jwkRequestsPerMin") as number,
    jwksUri: config.get("jwt.jwkUri") as string
  }),
  audience: config.get("jwt.audience") as string,
  issuer: config.get("jwt.issuer") as string,
  algorithms: config.get("jwt.algorithms") as string[],
})

I hope this helps!

@davidpatrick
Copy link
Contributor

Hey all, currently we are gating a lot of the agent options for the request, but what we are looking at doing is exposing the ability to completely override the agent used.

@davidpatrick davidpatrick added this to the v2-Next milestone Oct 15, 2020
@lhargil
Copy link

lhargil commented Oct 20, 2020

FYI: This is my workaround for the problem.

// TODO: Temporary fix until "node-jwks-rsa" project adds native support for the requestAgentOptions property.
// Extend ExpressJwtOptions interface.
// Must extend BEFORE we use jwksRsa.expressJwtSecret.
declare module "jwks-rsa" {
  interface ExpressJwtOptions {
    requestAgentOptions?: AgentOptions;
  }
}

jwt({
  // Dynamically provide signing keys 
  // provided by the JWKS endpoint.
  secret: jwksRsa.expressJwtSecret({
    strictSsl: true,
    requestAgentOptions: {
      ca: fs.readFileSync(path.resolve(__dirname, "ca.crt"), "utf8")
    },
    cache: config.get("jwt.cache") as boolean,
    rateLimit: config.get("jwt.rateLimit") as boolean,
    jwksRequestsPerMinute: config.get("jwt.jwkRequestsPerMin") as number,
    jwksUri: config.get("jwt.jwkUri") as string
  }),
  audience: config.get("jwt.audience") as string,
  issuer: config.get("jwt.issuer") as string,
  algorithms: config.get("jwt.algorithms") as string[],
})

I hope this helps!

I have encountered this problem as well. Currently building a Nestjs app.

Using your workaround, I can confirm that it works. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants