Giter Site home page Giter Site logo

Comments (4)

ironpark avatar ironpark commented on September 20, 2024 1

i have same problem.

import Koa from "koa";
import Router from "koa-router";
import jwt from "koa-jwt";
import { koaJwtSecret } from "jwks-rsa";
import { ApolloServer } from "apollo-server-koa";
import graphqlSchema from "./schema";

const graphqlServer = new ApolloServer({
  schema: graphqlSchema,
});

const app = new Koa();
const router = new Router();

app.use(
  jwt({
    secret: koaJwtSecret({
      cache: true,
      rateLimit: true,
      jwksRequestsPerMinute: 2,
      jwksUri: "test/jwks.json",
    }),
    audience: "http://myapi/protected",
    issuer: "http://issuer",
    algorithms: ["RS256"],
  }),
);
app.ts:28:7 - error TS2345: Argument of type '{ secret: (name: string, scheme: string, options?: any) => void; audience: string; issuer: string...' is not assignable to parameter of type 'Options'.
  Types of property 'secret' are incompatible.
    Type '(name: string, scheme: string, options?: any) => void' is not assignable to type 'string | string[] | Buffer | Buffer[] | SecretLoader'.
      Type '(name: string, scheme: string, options?: any) => void' is not assignable to type 'SecretLoader'.
        Type 'void' is not assignable to type 'Promise<string | string[] | Buffer | Buffer[]>'.

 28   jwt({
          ~
 29     secret: koaJwtSecret({
    ~~~~~~~~~~~~~~~~~~~~~~~~~~
...
 37     algorithms: ["RS256"],
    ~~~~~~~~~~~~~~~~~~~~~~~~~~
 38   }),
    ~~~

from node-jwks-rsa.

cocojoe avatar cocojoe commented on September 20, 2024

Care to share some information that would help address this issue?
What is your setup? What is the actual error message you are seeing?
Thx

from node-jwks-rsa.

asafigan avatar asafigan commented on September 20, 2024

Sorry, I was frustrated when I opened this issue so I didn't elaborate.

The types for hapiJwt2Key, hapiJwt2KeyAsync, and koaJwtSecret are all the same, which is not true. It looks like they were just copied and pasted for each other. koaJwtSecret is wrong; the others might be wrong too.

What it is now:

function koaJwtSecret(options: JwksRsa.Options): (name: string, scheme: string, options?: any) => void;

If you read the source code, the return type is completely wrong. It is more like:

function koaJwtSecret(options: JwksRsa.Options): (options: {alg: string, kid: string}) => Promise<string>;

I am not sure that the inputs and promise are all strings by reading just src/integrations/koa.js, but that is my best guess.

from node-jwks-rsa.

sjdweb avatar sjdweb commented on September 20, 2024

I'm having this problem too.

This should match the signature of SecretLoader in koa-jwt package.

export type SecretLoader = (header: any, payload: any) => Promise<string | string[] | Buffer | Buffer[]>;

You can shut the compiler up for the time being:

app.use(
  jwt({
    secret: koaJwtSecret({
      cache: true,
      rateLimit: true,
      jwksRequestsPerMinute: 2,
      jwksUri: "test/jwks.json",
    }) as jwt.SecretLoader,
    audience: "http://myapi/protected",
    issuer: "http://issuer",
    algorithms: ["RS256"],
  }),
);

from node-jwks-rsa.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.