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

Pass custom headers to the search plugin #6919

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pkukielka
Copy link
Contributor

@pkukielka pkukielka commented Feb 3, 2025

Problem description

With the uncommented configuration bellow it works (you need to paste valid token of course).

If I switch to X-Forwarded-User configuration (commented out) it fails with:

Access to fetch at 'https://piotr-kukielka.sgdev.dev/.api/graphql?SiteVersionAndCurrentUser' 
from origin 'http://piotr-kukielka.sgdev.dev' has been blocked by CORS policy: 
Request header field x-forwarded-user is not allowed by Access-Control-Allow-Headers in preflight response.

I suspect it might be due to http/https mismatch, see: #6919 (comment)
But If I try to keep https urls as they IMHO should be, it does not work with either config.

{
  "cody.override.serverEndpoint":  "https://piotr-kukielka.sgdev.dev",

  "cody.auth.externalProviders": [
    {
      "endpoint": "https://piotr-kukielka.sgdev.dev",
      "executable": {
        "commandLine": ["echo '{ \"headers\": { \"Authorization\": \"token sgp_local_YOUR_TOKEN\" } }'"],
        "shell": "/bin/bash"
      }
    },
//    {
//      "endpoint": "https://piotr-kukielka.sgdev.dev",
//      "executable": {
//        "commandLine": ["echo '{ \"headers\": { \"X-Forwarded-User\": \"SomeUser\" } }'"],
//        "shell": "/bin/bash"
//      }
//    }
  ]
}

Test plan

TBD

@pkukielka pkukielka marked this pull request as draft February 3, 2025 16:14
.registerSchemeHandlerFactory("http", "sourcegraph", new HttpSchemeHandlerFactory());
public SourcegraphJBCefBrowser(
@NotNull JSToJavaBridgeRequestHandler requestHandler, String endpointUrl) {
super(endpointUrl.replaceAll("/+$", "").replace("https://", "http://") + "/html/index.html");
Copy link
Contributor Author

@pkukielka pkukielka Feb 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing https to http with .replace("https://", "http://") seems unnecessary or even buggy.
But with it and Authorization: token it works.

Without that replace, even with the Authorization: token configuration it fails with Failed to load Sourcegraph settings TypeError: Failed to fetch.

Btw. when trying to switch to https I changed line 18 as well, of course.
Interesting note: if I add both http and https scheme handler factories it fails as well, even if replace is in place...

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 this pull request may close these issues.

1 participant