3

I have a WMS layer hosted on Geoserver that is being shown on a web map using the Google Maps API.

The problem is that for now I want to use basic authentication on the Geoserver. Every time you try to access the server (or the layer) in browser, it will ask for a username and password. (Note: The prompt only shows up on Firefox. Chrome just logs 401 errors in the console).

What I've been trying to do is authorize it in the background so the user does not have to enter any credentials. Here's what I tried.

  1. Before loading the map, send a request with credentials to fetch at least one tile: http://user:password@localhost:8080/geoserver/wms?layers=mosaic&version=1.1.1&Service=WMS&request=GetMap&Styles=&format=image%2Fpng&SRS=EPSG:4326&BBOX[my bounds]=&width=256&height=256. My server-side code is in Python so I used the requests library on that URL to at least get something about the layer, like status code or content type. This works fine.
  2. My assumption was that this would have authenticated the access to this layer (and server) for the user in the background.
  3. But when I load my WMS layer on my map, it will ask for authentication again on Firefox, and Chrome just logs 401 errors. The only difference is that in my JavaScript file, the URL is without user:password. I don't want to expose the credentials on the client-side.

What else can I try to work around this issue?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.