Repository navigation
Add Authentication header #1359
Description
Activity
Please read this discussion on the Leaflet issue tracker: Leaflet/Leaflet#2091
The TileLayer class doesn't support custom headers. At the bottom of the discussion they link to a JS plugin you could try.I don't suppose it's common to need authentication headers for tileservers. I thought they mostly pass the api key as part of the url or as a parameter. What tileserver are you using that requires authentication headers?
I'm using a tile server behind OAuth so I'm interested in this.
I'm trying to use a tile server that requires the api key to be passed on through header, so I am interested in this as well.
+1 Many Cloud providers require OAuth credentials to even reach the server, so I'm also interested in this.
- addedenhancementFeature request or idea about how to make folium betterFeature request or idea about how to make folium better
on Nov 18, 2022 +1
@Conengmo I am willing to take a stab at this.
Before I start though, I came up with three design alternatives. My preference would be option 1, but you decide. (Or propose something else altogether.)
Option 1
It is for use cases like this that I propose to introducefolium.Classwith anincludemethod.
Users would be able to implement the requested functionality like this:tiles = TileLayer() tiles.add_js_link("superagent", "https://cdnjs.cloudflare.com/ajax/libs/superagent/9.0.2/superagent.js") tiles.include(create_tile=JsCode(""" function(coords, done) { const url = this.getTileUrl(coords); const img = document.createElement('img'); superagent .get(url) .set(‘header’, ‘header value’) .responseType('blob') .then((response) => { img.src = URL.createObjectURL(response.body); done(null, img); }); return img; } """))** Option 2 **
As an alternative, I can create a newfolium.element.Includethat can be added usingadd_child.I don't like this option very much. The method
add_childwithIncludecan called on anybranca.element. Only for certain elements (the ones representing Leaflet classes) would it actually make sense. I am not afraid that people will try it, but it does not feel right.** Option 3 **
Implement this specifically onTileLayer. E.g. by adding a JsCode parameter to the constructor forcreate_tile.+1
I am working on a solution that builds on the code here: Leaflet/Leaflet#2091 (comment).
Is your feature request related to a problem? Please describe.
Add headers to the request, in order to implement Authentication against the server
Describe the solution you'd like
folium.Map(location=[45.372, -121.6972],
zoom_start=12,
tiles='http://{s}.tiles.yourtiles.com/{z}/{x}/{y}.png',
attr='My Data Attribution'),
headers: {"Authorization": "Bearer Token" }