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

koaJwtSecret type declaration is incorrect #46

Closed
asafigan opened this issue Jun 27, 2018 · 4 comments · Fixed by #80
Closed

koaJwtSecret type declaration is incorrect #46

asafigan opened this issue Jun 27, 2018 · 4 comments · Fixed by #80

Comments

@asafigan
Copy link

This is causing errors in my typeScript code.

@cocojoe
Copy link
Member

cocojoe commented Jul 11, 2018

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

@asafigan
Copy link
Author

asafigan commented Jul 11, 2018

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.

@ironpark
Copy link

ironpark commented Sep 12, 2018

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:https://myapi/protected",
    issuer: "http:https://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   }),
    ~~~

@sjdweb
Copy link

sjdweb commented Dec 5, 2018

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:https://myapi/protected",
    issuer: "http:https://issuer",
    algorithms: ["RS256"],
  }),
);

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

Successfully merging a pull request may close this issue.

4 participants