I'm managing a large QGIS project file that connect to several postgis layers.

Since this QGIS project file is used by many people, we set up a authentication config using the QGIS authentication system. Each layer of the project comes with an authentication number (let's say 1111111).

Whenever I need to add a new layer to this project, I have to manually enter the authentification number in the project file. So I edit the .qgs project file with a text editor and add authcfg=1111111 in 2 places, first in the <layer-tree-layer>layer definition and then in the <datasource>.

I find this quite cumbersome and I'd like my customers could do it by themselves without editing the qgs project file or using pyqgis. Is there a graphical user interface way to add this authcfg=1111111 in any layer of a QGIS project?

When looking at the layer properties, we can see this information (in the Information tab, for instance dbname='mydb' host=xxx.xxx.xxx.xxx port=5432 sslmode=disable authcfg=1111111 key='layer' srid=31370 type=Polygon checkPrimaryKeyUnicity='1' table="carto"."layer" (geom)) but there is no way to edit it.


There is a plugin that lets you change it easily, it's called "changeDataSource"

When you right-click on a layer, it will add a new choice in the menu (change vector datasource) which will popup a text edit box, where you can edit the datasource of the layer.

But, I found a simpler (yet convoluted) way. My projects are saved in a PostGIS database. So I added a trigger function on the qgis_projects table where they are saved, that changes the authcfg=xxxxx to whichever value I want, each time, on the save event.

But, QGIS does save the info there, in an XML form, but ZIPs it (no gzip, good ol' zip) so I need the Python programming language installed on the PostGIS server to do that.

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.