-
Notifications
You must be signed in to change notification settings - Fork 211
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 CORS handling for web-components #2006
base: main
Are you sure you want to change the base?
Conversation
…ng refs in HTTP served schemas.
@@ -1,2 +1,2 @@ | |||
// auto-updated during build | |||
export const appVersion = '1.6.7'; | |||
export const appVersion = '1.6.9'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, this isn't a change I made....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be automated...
const commonBundleOptions: $RefParser.Options = { | ||
continueOnError: true, | ||
resolve: { | ||
http: <$RefParser.HTTPResolverOptions>{ withCredentials }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the key needed change to modify how json-schema-ref-parser
fetches remote refs.
✔️ Deploy Preview for stoplight-elements ready! 🔨 Explore the source changes: 2eead18 🔍 Inspect the deploy log: https://app.netlify.com/sites/stoplight-elements/deploys/61f42191205c000008081f10 😎 Browse the preview: https://deploy-preview-2006--stoplight-elements.netlify.app |
✔️ Deploy Preview for stoplight-elements-demo ready! 🔨 Explore the source changes: 2eead18 🔍 Inspect the deploy log: https://app.netlify.com/sites/stoplight-elements-demo/deploys/61f42191ec359b000839f5ba 😎 Browse the preview: https://deploy-preview-2006--stoplight-elements-demo.netlify.app/ |
✔️ Deploy Preview for stoplight-elements-dev-portal-storybook ready! 🔨 Explore the source changes: 2eead18 🔍 Inspect the deploy log: https://app.netlify.com/sites/stoplight-elements-dev-portal-storybook/deploys/61f42191a08c73000781cb0e 😎 Browse the preview: https://deploy-preview-2006--stoplight-elements-dev-portal-storybook.netlify.app |
✔️ Deploy Preview for stoplight-elements ready! 🔨 Explore the source changes: f76c429 🔍 Inspect the deploy log: https://app.netlify.com/sites/stoplight-elements/deploys/622a339bfc4f18000be29d62 😎 Browse the preview: https://deploy-preview-2006--stoplight-elements.netlify.app |
✔️ Deploy Preview for stoplight-elements-demo ready! 🔨 Explore the source changes: f76c429 🔍 Inspect the deploy log: https://app.netlify.com/sites/stoplight-elements-demo/deploys/622a339bdc55b00009ae93b9 😎 Browse the preview: https://deploy-preview-2006--stoplight-elements-demo.netlify.app/ |
✔️ Deploy Preview for stoplight-elements-dev-portal-storybook ready! 🔨 Explore the source changes: f76c429 🔍 Inspect the deploy log: https://app.netlify.com/sites/stoplight-elements-dev-portal-storybook/deploys/622a339bdfaa3b0008f84f23 😎 Browse the preview: https://deploy-preview-2006--stoplight-elements-dev-portal-storybook.netlify.app |
We just ran into this today, amazing that this PR was already open. Thanks so much @danpat! |
Does @mmiask or @mnaumanali94 (or anyone else!) have any time to take a look at this? It would be really awesome to have this functionality! |
In the case @smores and I are hitting it's actually not even a cross-origin request, but it looks like this project is using a fork of |
I think |
Hi @danpat! Thanks for contributing to our OSS project! We'll work on getting this reviewed within the next couple weeks. I just wanted to keep you updated. |
@danpat is your need for actual cross-origin requests, or just same-origin requests with credentials? When I dug into this, I determined that if the build were not using a fork of https://github.com/jhiesey/stream-http/blob/master/lib/request.js#L148 Since none of this |
@tilgovi Mine is a same-origin situation. Our setup is:
components:
schemas:
SubSchema:
$ref: "./subschema.yaml" The core issue is that when the remote fetch for https://example.com/myschema/subschema.yaml happens, no cookies are included, so our authentication gateway intercepts the request and returns a 304 redirect to an authentication page. |
My team is having exactly the same problem as @danpat described -- we have an authentication proxy in a same-origin setup with an application that embeds Stoplight Elements. Requests issued by Stoplight lack the Any mechanism that adds pass a parameter to the Stoplight Elements React component letting us specify to use By the principle of least privilege, we would prefer the ability to set As an aside, thanks for the fantastic PR @danpat -- this is exactly the kind of change I was looking for! |
Looks like I am facing the same issue when serving apidocs via "Internal" github pages. With sub-schema reference it tries to hit github auth endpoint and fails with CORS access error. |
based on this PR stoplightio#2006
based on this PR stoplightio#2006
Is there any update on this? |
I still think this could be solved for most users by fixing the fork of json-schema-ref-parser. The fork being used here uses isomorphic-fetch and specifies |
based on this PR stoplightio#2006
based on this PR stoplightio#2006
based on this PR stoplightio#2006
Hello guys, any update? I solved this problem by modify the compiled js file every time. add It's very, very ungraceful, but I have no choice. |
based on this PR stoplightio#2006
based on this PR stoplightio#2006
based on this PR stoplightio#2006
@danpat I know this took a bit, but if you can please resolve the conflicts, we're good to review and merge this. |
CONTRIBUTING.md
I found myself using
elements
to create an online schema viewer that lives behind an authenticated proxy. Things mostly worked, except for parts of our schema that were remote$ref
references in the primary schema document. Whenelements
attempted to resolve them in our environment, the browser console log exploded with CORS-related errors.After a bunch of digging, it turned out that by default,
elements
was leaving@stoplight/json-schema-ref-parser
use it's default HTTP resolver settings, which has hascredentials: 'omit'
in the options passed tofetch()
. This fails when CORS headers are required.This PR doesn't change the default, but exposes a new option to the
elements-api
tag calledwithCredentials
that is passed through to@stoplight/json-schema-ref-parser
, allowing user control over whether CORS handling is enabled or not.I'm not a front-end person by default, so apologies if the style of this PR is out of line, or if I've missed something fundamental. These changes appear to be functioning as intendent in the environment where I have them deployed.