emilhe / dash-leaflet

MIT License
204 stars 33 forks source link

Basic authorization for WMSTileLayer #216

Open MVennebusch opened 8 months ago

MVennebusch commented 8 months ago

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

prl900 commented 8 months ago

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"))
emilhe commented 8 months ago

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

prl900 commented 8 months ago

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 commented 6 months ago

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