R leaflet wms authorization header

Hi,
Can anyone please tell me if it is possible to include an Authorization request header when with R Leaflet WMS? I tried the following Javascript plugin. https://github.com/ticinum-aerospace/leaflet-wms-header It gives me the error below. I am not good at JS and I am not sure what went wrong.

I aso saw Kent37 posted a solution last year:


has anyone been able to make it work? Thanks.

1 Like

What is your R code? I am using a version of the code I posted with no issues.

Thanks for your reply. Would you mind if I ask if L.TileLayer.xhr you used is a plugin you develop youself? I could not find it anywhere. Thanks. My codes are below:

wms_headerPlugin <- htmlDependency("leaflet-wms-header","1.0.8",
src = normalizePath("D:/API/www/leaflet-wms-header/"),
script="index.js")
registerPlugin <- function(map, plugin) {
map$dependencies <- c(map$dependencies, list(plugin))
map
}

leaflet() %>% addTiles() %>%
setView(145.98705368, -36.56692057, 14)%>%

registerPlugin(wms_headerPlugin) %>%
onRender("
function(el, x,data) {
var xhrLayer = new L.TileLayer.wmsHeader(
'https://xxx.com/api/wms',
{
layers: 'xxxx',
service: 'wms',
format: 'image/png',
version: '1.3.0',
TIME: '2020-01-01T00:00:00Z/2021-01-01T00:00:00Z',
crs: 3857,
VARIABLECODES: 'xxx',
EXCEPTIONS: 'xxx',
request: 'xxx',
ORGANISATIONID:xxxx
}
, [
{ header: 'Authorization', value: 'Bearer token'},
{ header: 'content-type', value: 'text/plain'},
],null)
.addTo(this);
}")

Sorry, I thought my plugin was public but it is not at this time.

Looking at your code, a couple of things I see:

  • You may need a ? at the end of your URL, that is what the wms example uses.
  • You don't need to call addTile, your wmsHeader replaces that.
  • Are you using an actual token value where you have 'Bearer token'?

HTH

Hi Kent,
I have tried those options (? and remove addTile )and they did not seem to work. Yes, I have a token. I was able to get the png from the server with a normal GET API call. Did you try the leaflet-wms-header plugin? Any chance I can ask the name of the plugin you used? I might look around and see if I can still get it somewhere. Thanks again for answering my questions.

Y

I have not tried leaflet-wms-header. My application uses XYZ tiles, not WMS. Sorry I don't think I can help you any further.

Hi Kent, Thanks for your clarificaiton.