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

"this" is undefined in JwksClient #122

Closed
Schwusch opened this issue Jan 22, 2020 · 1 comment
Closed

"this" is undefined in JwksClient #122

Schwusch opened this issue Jan 22, 2020 · 1 comment

Comments

@Schwusch
Copy link

Schwusch commented Jan 22, 2020

Environment

Using 1.6.2 with nodejs10.x in AWS Lambda:

"TypeError: Cannot read property 'logger' of undefined","at getKeys (/var/task/node_modules/jwks-rsa/lib/JwksClient.js:87:12)"

Reproduction

This is consistently reproducable by running this code:

import util from "util";
import jwksClient from "jwks-rsa";

const client = jwksClient({
            cache: true,
            cacheMaxEntries: 50,
            cacheMaxAge: 2 * 60 * 1000,
            jwksUri: secretUrl,
            requestHeaders: secretHeaders
        });

const getKeys = util.promisify(client.getKeys);
const keys = await getKeys()
@davidpatrick
Copy link
Contributor

@Schwusch promisifying client.getKeys changes the local scope of the getKeys function. You will need to rebind the client scope to the promisifyed function

util.promisify(client.getKeys).bind(client);

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

No branches or pull requests

2 participants