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

Add additional fetch options #255

Closed
wants to merge 1 commit into from

Conversation

OwenDelahoy
Copy link

@OwenDelahoy OwenDelahoy commented Sep 2, 2021

Thank you for the fantastic library of JSON Web functions.

I have been trying to use jose-browser-runtime/jwks/remote inside Cloudflare workers
Although the code executes server side, the Cloudflare workers environment lacks many of node-js libraries. The environment is much more similar to a web worker running insider a browser.

Cloudflare provides a fetch function very similar to the standard fetch function, however Cloudflare's Request parameter lacks some of the properties in the standard Request parameter.

Unfortunately, if the user provides Request parameter options such as mode , credentials or referrerPolicy, then Cloudflare's fetch function will throw an error of the form

The 'mode' field on 'RequestInitializerDict' is not implemented.

Other libraries such as the aws sdk have encounter similar issues while being used inside cloudflare workers.
aws/aws-sdk-js-v3#1165

Currently these parameters are specified by the library and can not be configured.
https://github.com/panva/jose/blob/main/src/runtime/browser/fetch_jwks.ts#L15-L17

This pull request allows the user to configure/override these default parameters with undefined values, so that it can be used inside cloudflare workers.

@panva
Copy link
Owner

panva commented Sep 2, 2021

@OwenDelahoy thank you for bringing this up, I wasn't aware of CF workers specifics until now. I'm fine adding runtime specific options but, similar to Node.js's agent these should be a single parameter typed any documented to be fetch based runtime specific and not applicable to Node.js.

Thinking about it further it may be shared between runtimes and simply applied to both fetch() and http(s)(url, { ... options }), but it still be any as these are runtime specific options that the types cannot account for.

Let me make up my mind first, I don't want to open this up too much as to not allow myself the leeway of changing the implementation later. I do want to account for only the options that block you in CF workers as well, setting headers, allowing redirects, referrer or changing the method is not what i wish to support.

@panva
Copy link
Owner

panva commented Sep 2, 2021

How can one detect from e.g. globalThis that it is run in CloudFlare workers? Because if that's detectable I would just unset the properties that aren't implemented by CF.

@github-actions github-actions bot closed this in ced065a Sep 2, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Dec 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants