folium icon indicating copy to clipboard operation
folium copied to clipboard

Add Authentication header

Open hitokiri opened this issue 4 years ago • 6 comments

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" }

hitokiri avatar Jun 18 '20 20:06 hitokiri

Please read this discussion on the Leaflet issue tracker: https://github.com/Leaflet/Leaflet/issues/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?

Conengmo avatar Jun 19 '20 06:06 Conengmo

I'm using a tile server behind OAuth so I'm interested in this.

bkanuka avatar Feb 12 '21 01:02 bkanuka

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.

Yasharesk avatar Feb 27 '21 17:02 Yasharesk

+1 Many Cloud providers require OAuth credentials to even reach the server, so I'm also interested in this.

davidcavazos avatar Oct 06 '21 22:10 davidcavazos

+1

PhilippBuehlerOkeanos avatar May 17 '24 10:05 PhilippBuehlerOkeanos

@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 introduce folium.Class with an include method. 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 new folium.element.Include that can be added using add_child.

I don't like this option very much. The method add_child with Include can called on any branca.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 on TileLayer. E.g. by adding a JsCode parameter to the constructor for create_tile.

hansthen avatar May 19 '24 09:05 hansthen