I am trying to use OpenLayers 2.12 to display WMS layers from a server which has HTTP Basic Authentication enabled.
I have tried to handle the authentication by putting the username and password in the URL parameter in my JavaScript code. Example layer creation:
myLayer = new OpenLayers.Layer.WMS('background',
'https://username:password@ws.nls.fi/rasteriaineistot/image?',
{
layers: 'background',
bbox: '-380188,6249943,1347312,8226943'
},
{
displayInLayerSwitcher: true,
isBaseLayer: false,
projection: 'EPSG:3067',
visibility: true
});
Of course this is not secure since the credentials are stored in JavaScript code and does not work in all browsers. Internet Explorer 8 gives security error pointing to OpenLayers.js and refuses to display the map at all. Firefox 13 pops up some authentication dialogs which I can cancel(the map displays correctly after that). In Chrome 23 the authentication seems to work flawlessly.
Can you confirm that it is not possible to handle the HTTP basic authentication in a cross-browser manner by encoding it in the URL and giving it to OpenLayers like in the example?
Can you suggest alternative ways to handle the HTTP basic authentication so that it works transparently to the user (no authentication popups displayed)? Perhaps use some kind of proxy server to work around this.