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

Cannot provide custom HTTP headers (e.g. bearer token) to Mapbox layer source #4566

Open
bchretien opened this issue Apr 4, 2024 · 2 comments

Comments

@bchretien
Copy link

Hi!

I wanted to display a Mapbox layer that requires authentication through bearer tokens, i.e. when doing something like:

fig.update_layout(
    mapbox_style="white-bg",
    mapbox_layers=[
        {
            "below": 'traces',
            "sourcetype": "raster",
            "sourceattribution": "My private ortho",
            "source": [
                "https://my_private_source.com/MapServer/tile/{z}/{y}/{x}"
            ]
        }
      ]
)

I need to pass custom HTTP headers to each tile request. In JavaScript, this can be easily achieved with the Mapbox API thanks to transformRequest (see here):

const map = new mapboxgl.Map({
  container: 'map',
  center: [2.35, 48.86],
  zoom: 13,
  transformRequest: (url, resourceType) => {
    if (url.startsWith('https://my_private_source.com')) {
      return {
        url: url,
        headers: { 'Authorization': 'Bearer ' + my_private_token }
      }
    }
  }
});

However, this does not seem supported by plotly.py, or am I missing something? With some pointers I could work on a PR, but I'm not sure where to start in the code base.

@TillerBurr
Copy link

TillerBurr commented Apr 7, 2024

I think this is something that would need to happen in plotly.js. Most of the plots are autogenerated from there. Here is the initial creation of the map object:
https://github.com/plotly/plotly.js/blob/d20b8e22370a28116c1276159a0e666e73cba5ae/src/plots/mapbox/mapbox.js#L98-L114

From my minimal research, it looks like either the entire map object would have to be recreated or create a new request manager on the map.
https://github.com/plotly/mapbox-gl-js/blob/52fa02f543e8403946a861b4736261561b2a2b6b/src/ui/map.js#L404

@bchretien
Copy link
Author

@TillerBurr thanks a lot for the information! I'll keep you posted once I start working on this (not sure when).

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

No branches or pull requests

2 participants