dash-leaflet icon indicating copy to clipboard operation
dash-leaflet copied to clipboard

Basic authorization for WMSTileLayer

Open MVennebusch opened this issue 2 years ago • 4 comments

Hello,

I am trying to use a WMS service with "basic authentification". Can I use WMSTileLayer and set the user and password somehow?

Thanks a lot, Markus

MVennebusch avatar Nov 17 '23 13:11 MVennebusch

Just wanted to say that accessing secured layers through WMSTileLayer would be something very useful for me too. In my case a token passed through the GET headers request similar to #213 would be enough.

@MVennebusch, not sure how your WMS server works but maybe you could try passing the user/password as extra custom parameters using something similar to this?:

dl.WMSTileLayer(url="https://your-server/wms/", layers="your_layer", 
                format="image/png", transparent=True,
                params=dict(user="me", password="secret"))

prl900 avatar Nov 19 '23 12:11 prl900

@MVennebusch / @prl900 do you have a (publicly accessable) example URL that I could use for testing a potential implementation?

emilhe avatar Nov 23 '23 19:11 emilhe

Thanks @emilhe, in our case, this is an example showing how it could work in dash-leaflet:

headers = {
    'x-api-key': '00000000000000000'
}

dl.WMSTileLayer(id="wms-class", url="https://api.terrak.io/wms", layers="", 
                params={"expression": "MSWX.air_temperature@(year=2021, month=3)", "vmin": 0, "vmax": 30}, 
                headers=headers)

Where the headers prop expects a dictionary containing the API key (or other information for the server).

This could be then injected into the GET call in Python with something like:

requests.get(url, params=params, headers=headers)

But I imagine this will need to be done in Javascript or using the Leaflet JS library, not sure how that works...

Note the WMS server doesn't use authentication at the moment but if we can receive the headers in the WMS calls, we should be good.

prl900 avatar Nov 24 '23 05:11 prl900

Just wondering if there are any updates about this issue. It might be more complicated than expected?

prl900 avatar Jan 02 '24 10:01 prl900