5

QGIS allows us to use any HTML in the map tip which can be used to show a corresponding image for a hovered feature in the map.

Example of such a code in the map tip definition:

<img src="http://imageserver.com/images/features/[% "id" %]" width="600"></img>

However, the server resource may require authentication. How to satisfy the server authentication requirement from the QGIS? How to supply the required credentials to be used in the image request?

Our server uses the basic authentication.

What I have tried:

  1. Just let show the map tip in hope that QGIS prompts a login dialog. It did not happen.

  2. I provided the authentication credentials in the "Options / Authentication" for the same base URL but it does not work. The QGIS seems to not respect the options. enter image description here

I am still not getting the picture but just an error image placeholder: enter image description here

I can clearly see from the server logs the requests are not authenticated and resulting in the 401 HTTP error.

EDIT 2 If you want to experiment, here is a simple Python script which is a HTTP web server with a basic authentication and hardcoded user "demouser" and password "demopass".

https://pastebin.com/vSQ9Le3C

Start the script python .\imgsrv.py. The server listens on http://localhost:8090/ and returns an image from the Pixabay.

Unfortunately, even this map tip in QGIS with this server does not work: <img src="http://demouser:demopass@localhost:8090"></img>

4
  • Welcome to Geographic Information Systems! Welcome to GIS SE! We're a little different from other sites; this isn't a discussion forum but a Q&A site. Your questions should as much as possible describe not just what you want to do, but precisely what you have tried and where you are stuck trying that. Please check out our short tour for more about how the site works
    – Ian Turton
    May 31, 2021 at 16:43
  • Hi @IanTurton, thank you for welcoming. I think that I followed all the guidelines and provided a question with steps I have tried; however I edited the description to be more clear about the steps.
    – Andrej Jel
    May 31, 2021 at 17:18
  • If you look at the "Installed Plugins" options in the authentication dialog you'll see which bits of QGIS the authentication works with - plain URLs in bits of HTML in QGIS won't hit the authentication-lookup mechanism, which is why this doesn't work. Possible workaround in answer below.
    – Spacedman
    May 31, 2021 at 18:54
  • I looked it up in the "Installed Plugins" and see that Basic authenticated is being triggered for "postgres, oracle, db2, ows, wfs, wcs, wms, ogr, gdal, proxy". Useful information, thank you.
    – Andrej Jel
    Jun 3, 2021 at 15:28

1 Answer 1

3

Another option is to use the fact that HTTP Basic Auth info can be put in the URL.

To see this in action in your browser, there's a test service here:

https://authenticationtest.com/

which has a Basic Auth test here:

https://authenticationtest.com/HTTPAuth/

When clicked it should ask for username ("user") and password ("pass") - but don't fill them in. Instead go to:

https://user:pass@authenticationtest.com/HTTPAuth/

which should let you in without a login prompt.

You should be able to put this as the URL in your QGIS dialog, ie:

http://username:password123@imageserver.com/

but its generally a bad idea to stick plain text passwords in a URL... If I can get round to setting up a Basic Auth web service with some images in I might see if I can get QGIS to talk to it...

1
  • Hi @Spacedman, thanks for your answer but I have not managed even with this approach. If you want to experiment, here is a single Python script that I wrote: pastebin.com/vSQ9Le3C which is just a simple HTTP server with basic authorization and user demouser/demopass. It returns an JPEG image from Pixabay. I will append more info in the question.
    – Andrej Jel
    Jun 3, 2021 at 8:57

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.