Skip to content

Add Authentication header #1359

Description

@hitokiri

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

Activity

  1. Conengmo commented on Jun 19, 2020

    @Conengmo
    Member

    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?

  2. bkanuka commented on Feb 12, 2021

    @bkanuka

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

  3. Yasharesk commented on Feb 27, 2021

    @Yasharesk

    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.

  4. davidcavazos commented on Oct 6, 2021

    @davidcavazos

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

  5. added
    enhancementFeature request or idea about how to make folium better
    on Nov 18, 2022
  6. PhilippBuehlerOkeanos commented on May 17, 2024

    @PhilippBuehlerOkeanos

    +1

  7. changed the title [-]Add Authtication header[/-] [+]Add Authentication header[/+] on May 18, 2024
  8. hansthen commented on May 19, 2024

    @hansthen
    Collaborator

    @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.

  9. james-hinton commented on May 20, 2025

    @james-hinton

    +1

  10. hansthen commented on Jun 10, 2025

    @hansthen
    Collaborator

    I am working on a solution that builds on the code here: Leaflet/Leaflet#2091 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementFeature request or idea about how to make folium better

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      Sponsor
      SponsoredKunjungi sekarang
      Promo