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

[BUG] Improve discoverability of the timeout parameter for fetch requests (in docs and/or code) #133

Open
DannyBoris opened this issue Aug 4, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@DannyBoris
Copy link

Describe the bug
Please provide a clear and concise description of what the bug is.
Trying to decode a token generated by Cognito results in Failed to fetch jwks.
I've double checked all credentials (AWS_COGNITO_USER_POOL_ID, AWS_COGNITO_CLIENT_ID)

fetch the raw URL of the jwks from amazon works well - The json is retrieved.

Versions
Which version of aws-jwt-verify are you using? 4.0.0
Are you using the library in Node.js or in the Web browser? Postman/Browser
If Node.js, which version of Node.js are you using? (Should be at least 14)
If Web browser, which web browser and which version of it are you using? 20.4.0
If using TypeScript, which version of TypeScript are you using? (Should be at least 4) 5.1.6

To Reproduce
If you can, please provide a minimal code example that reproduces the bug.
const decoded = await verifier.verify(token);

@DannyBoris DannyBoris added the bug Something isn't working label Aug 4, 2023
@DannyBoris
Copy link
Author

Seems like the problem is a timeout after 1500 which is the default.
When increasing the timeout to 5000, the request process successfully.

    async getJwks(jwksUri) {
        const existingFetch = this.fetchingJwks.get(jwksUri);
        if (existingFetch) {
            return existingFetch;
        }
        **const jwksPromise = this.fetcher.fetch(jwksUri, { responseTimeout: 5000 }).then((res) => {**
            assertIsJwks(res);
            return res;
        });
        this.fetchingJwks.set(jwksUri, jwksPromise);
        let jwks;
        try {
            jwks = await jwksPromise;
        }
        finally {
            this.fetchingJwks.delete(jwksUri);
        }
        this.jwksCache.set(jwksUri, jwks);
        return jwks;
    }

@DannyBoris
Copy link
Author

DannyBoris commented Aug 4, 2023

Seems like the problem is a timeout after 1500 which is the default.
When increasing the timeout to 5000, the request process successfully.

    async getJwks(jwksUri) {
        const existingFetch = this.fetchingJwks.get(jwksUri);
        if (existingFetch) {
            return existingFetch;
        }
        **const jwksPromise = this.fetcher.fetch(jwksUri, { responseTimeout: 5000 }).then((res) => {**
            assertIsJwks(res);
            return res;
        });
        this.fetchingJwks.set(jwksUri, jwksPromise);
        let jwks;
        try {
            jwks = await jwksPromise;
        }
        finally {
            this.fetchingJwks.delete(jwksUri);
        }
        this.jwksCache.set(jwksUri, jwks);
        return jwks;
    }

Is it possible to expose timeout setting to the user?

@ottokruse
Copy link
Contributor

The timeout is user exposed: https://github.com/awslabs/aws-jwt-verify#configuring-the-jwks-response-timeout-and-other-http-options-with-jsonfetcher

See also this comment: #72 (comment)

Let's leave this issue open because you have convinced me we need to do a better job of making this setting more obvious.

@ottokruse ottokruse changed the title [BUG] Getting Failed to fetch https://cognito-idp.<region>.amazonaws.com/<region+client_id>/.well-known/jwks.json [BUG] Improve discoverability of the timeout parameter for fetch requests (in docs amd/or code) Oct 19, 2023
@ottokruse ottokruse changed the title [BUG] Improve discoverability of the timeout parameter for fetch requests (in docs amd/or code) [BUG] Improve discoverability of the timeout parameter for fetch requests (in docs and/or code) Oct 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants