GMOD / JBrowseR

R interface to the JBrowse 2 Linear Genome View.
https://gmod.github.io/JBrowseR/
Apache License 2.0
35 stars 3 forks source link

How to modify request headers #26

Closed Imoteph closed 1 year ago

Imoteph commented 1 year ago

Hi,

is there a way to modify the HTTP request headers that JBrowseR sends? I have got a flask server providing the data via stream and an R app set up. Now I would like to modify the request headers, that are being sent to the flask server, from the R side by adding an additional field. I suspect the headers are currently created somewhere in the JS backend and only the request bodies are created as JSONs in R, right?

Thanks a lot!

cmdcolin commented 1 year ago

are you referring to requests for general data files like bam, vcf, etc? we have the concept of 'internetaccounts' that can modify headers and such but it is a little advanced (and I haven't tested those in JBrowseR either)

Imoteph commented 1 year ago

Yes indeed, the data are contents of the bams, As mentioned, I have a flask server which I need to secure at least with an API key that needs to be sent by the shiny app for every request, to secure that only this application gets access. Hence I would like to add some information to the HTTP request header

cmdcolin commented 1 year ago

If you are not totally tied to JBrowseR, you could use our 'embedded components' potentially, and we have examples of using the "internet accounts" this way.

here is the example with using internetAccounts for our embedded components https://jbrowse.org/storybook/lgv/main/?path=/docs/using-internetaccounts--docs (you can open the track selector on this page and see that it pops up a dialog to enter an oauth token when you turn on the "google drive bigwig" track)

Source code for that example https://github.com/GMOD/jbrowse-components/blob/main/products/jbrowse-react-linear-genome-view/stories/examples/WithInternetAccounts.tsx

The internet accounts are specified in the config by adding a internetAccountId alongside the uri. the ExternalOAuthToken internetAccount type prompts the user for a OAuth token on opening the track. we could make another example so that instead of prompting, you supply the token via the config also

I am new to JBrowseR as a maintainer (I mostly work on the core codebase including the embedded components, but I have taken on some maintainership of JBrowseR) but if you are invested in using JBrowseR let me know and I can do some investigation for how to set this up in JBrowseR

Imoteph commented 1 year ago

Thanks for the links and help so far!

But unfortunately, I am completely tied to JbrowseR, as the mail application is a shiny App, where the requested data is then shown. It would be super nice and helpful if you find some time to investigate how this is set in JBrowseR

Imoteph commented 1 year ago

Hi @cmdcolin

did you find some time to dive a bit into JbrowseR how to set up this request?

cmdcolin commented 1 year ago

I just started a possible approach here to add plugins, and the plugins could add a internetaccount. thanks for the ping though...this PR is not complete as posted but will let you know when I get update

https://github.com/GMOD/JBrowseR/pull/27

cmdcolin commented 1 year ago

I have continued some work on this with creating a demo plugin that can add custom HTTP headers (https://github.com/cmdcolin/jbrowse-plugin-modifyhttpheaders) and pushed forward this branch a little bit. Haven't fully tested this in JBrowseR land yet but will keep you posted. if you can confirm you're still interested in this, will keep me motivated on it :)

cmdcolin commented 1 year ago

current PR progress here, allows adding plugins from HTTP urls and custom internet accounts

cmdcolin commented 1 year ago

specific code that is adding the custom header https://github.com/cmdcolin/jbrowse-plugin-modifyhttpheaders/blob/main/src/index.ts#L37-L46

Imoteph commented 1 year ago

I have continued some work on this with creating a demo plugin that can add custom HTTP headers (https://github.com/cmdcolin/jbrowse-plugin-modifyhttpheaders) and pushed forward this branch a little bit. Haven't fully tested this in JBrowseR land yet but will keep you posted. if you can confirm you're still interested in this, will keep me motivated on it :)

Yes, I am still interested!! Looking forward to see how this then can be used into JbrowseR.

Imoteph commented 1 year ago

And thanks for the update!

Imoteph commented 1 year ago

@cmdcolin

don´t take it as push :) . Just wanted to know if you have some further news to this topic.

cmdcolin commented 1 year ago

no news yet, apologies. will keep you posted

not sure if it helps but one strategy for you could be to put something like a proxy that adds the particular http header of interest, or avoid the check for the http header entirely (if there is any particular context for why the header is needed let me know though)

cmdcolin commented 1 year ago

I finally managed to make a demo that accomplishes this (adding a request header to file requests from jbrowse using a plugin). It requires installing the current github dev release with devtools::install_github('GMOD/JBrowseR') right now, but will make it CRAN release hopefully soon

Using JBrowse2 plugins with JBrowseR requires hosting them at an HTTP location right now (so e.g. I uploaded that plugin to a S3 bucket), and also needs to use the "JsonView" version

Example here

https://github.com/GMOD/JBrowseR/blob/main/example_apps/using_plugins/config.json https://github.com/GMOD/JBrowseR/blob/main/example_apps/using_plugins/app.R

The plugin code is here

I made this plugin https://s3.amazonaws.com/jbrowse.org/demos/jbrowse-plugin-modifyhttpheaders.umd.development.js

You can see the adds the header "ExtraHTTPHeader: Wow" to your requests

Thanks for your patience and let me know if there are any questions, I know it's a pretty raw example but it should allow it to be extended for custom use cases

cmdcolin commented 1 year ago

as far as for how you would use this: I would

a) download the plugin I linked above b) change the header to what you are interested in c) re-upload the plugin to a http URL d) change the URL in the config.json for the plugin to your new http URL

cmdcolin commented 1 year ago

and then

e) edit the config.json with your tracks and add the internetAccountId to them, which tells it to use the ModifyHTTPHeaders internet account plugin

Imoteph commented 1 year ago

Thanks a lot for your work, we will have a look into this and will leave a feedback! Thanks again!

Imoteph commented 1 year ago

As promised the feedback,

First of thanks for all the work you already put into this Request! We highly appreciate this. We had a careful look into it and decided against this approach. The problem for us is that with the solution we need to safely store the jbrowse-plugin-modifyhttpheaders.umd.development.js away for each different jbrowse user/instance and again have the problem of how to deploy this safely.

Instead, we create now inside the shiny server a browse instance that is only alive/reactive/known in the session itself.

Again thanks for all the work and your effort here!!

cmdcolin commented 1 year ago

gotcha no worries. I think it's great you can find a workable solution still and thanks for reporting the cram-js issue!

cmdcolin commented 1 year ago

can maybe close this issue for now...will hopefully get this properly published to CRAN soon :)