<div dir="ltr">definetvely string<div><br></div><div>you should always use quir.uri(False) otherwise the credentail wil be expanded in the uri string. Usually you should add authId in the uri string ot the layer that is the ID used to point to the QGIS AuthDB. credenial (piointed by the authId) will be managed (depending on auth mode) trasparently and safely by the data provider.</div><div><br></div><div>about documentation... the AuthManager singleton has been moved slowly to QgsApplication (slower that other signleton) that's the reason the documentation has been not updated accordingly, thank to spot it... can you open a documentation issue for that? similar for extra brackets... I ask you to do it, just because I do not have a documentation setup in thi smmeont to update it directly... you can freely assign to me the documentation issue.</div><div><br></div><div>about the issue you have with GetCapabilities, probably you have to use the opportune QByteArray to QString conversion that involve codec.... just my 2c</div><div><br></div><div>cheers<br clear="all"><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><br></div><div>Luigi Pirelli<br><br>**************************************************************************************************<br>* LinkedIn: <a href="https://www.linkedin.com/in/luigipirelli" target="_blank">https://www.linkedin.com/in/luigipirelli</a><br>* Stackexchange: <a href="http://gis.stackexchange.com/users/19667/luigi-pirelli" target="_blank">http://gis.stackexchange.com/users/19667/luigi-pirelli</a><br>* GitHub: <a href="https://github.com/luipir" target="_blank">https://github.com/luipir</a><br>* Book: <a href="https://www.packtpub.com/eu/application-development/mastering-geospatial-development-qgis-3x-third-edition" target="_blank">Mastering QGIS3 - 3rd Edition</a></div><div>* Hire a team: <a href="http://www.qcooperative.net" target="_blank">http://www.qcooperative.net</a><br>**************************************************************************************************</div></div></div></div></div></div></div></div></div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, 26 Jul 2019 at 11:33, Paul Wittle <<a href="mailto:paul.wittle@dorsetcouncil.gov.uk">paul.wittle@dorsetcouncil.gov.uk</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">





<div lang="EN-GB">
<div class="gmail-m_-3900278500333994519WordSection1">
<p class="MsoNormal"><span>Hi,<u></u><u></u></span></p>
<p class="MsoNormal"><span><u></u> <u></u></span></p>
<p class="MsoNormal"><span>I think I might have just spotted the issue with my code.
<u></u><u></u></span></p>
<p class="MsoNormal"><span><u></u> <u></u></span></p>
<p class="MsoNormal"><span>If you do quir.encodedUri() you get an error in version 3.4 because it is expecting a string but encodedUri returns a ByteArray. If you wrap it in the str() function you get a result because the
 result in now a string however it is a string which has b’ a the front and a trailing ‘ at the end.
<u></u><u></u></span></p>
<p class="MsoNormal"><span><u></u> <u></u></span></p>
<p class="MsoNormal"><span>I believe the trailing ‘ is being taken literally and the resulting getCapabilities statement is for
<a href="https://domain.name/wms'?request=GetCapabilities" target="_blank">https://domain.name/wms’?request=GetCapabilities</a><u></u><u></u></span></p>
<p class="MsoNormal"><span><u></u> <u></u></span></p>
<p class="MsoNormal"><span>If you use quir.uri() it doesn’t work and neither does quir.uri(False) so what should I be using there or should the QgsRasterLayer function just be accepting a ByteArray or String?<u></u><u></u></span></p>
<p class="MsoNormal"><span><u></u> <u></u></span></p>
<p class="MsoNormal"><span>Thanks,<u></u><u></u></span></p>
<p class="MsoNormal"><span>Paul<u></u><u></u></span></p>
<p class="MsoNormal"><span><u></u> <u></u></span></p>
<div>
<div style="border-right:none;border-bottom:none;border-left:none;border-top:1pt solid rgb(225,225,225);padding:3pt 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US">From:</span></b><span lang="EN-US"> Paul Wittle
<br>
<b>Sent:</b> 26 July 2019 08:23<br>
<b>To:</b> DelazJ <<a href="mailto:delazj@gmail.com" target="_blank">delazj@gmail.com</a>><br>
<b>Cc:</b> <a href="mailto:qgis-user@lists.osgeo.org" target="_blank">qgis-user@lists.osgeo.org</a><br>
<b>Subject:</b> RE: [Qgis-user] Using QgsAuthManager<u></u><u></u></span></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><span>Hi,<u></u><u></u></span></p>
<p class="MsoNormal"><span><u></u> <u></u></span></p>
<p class="MsoNormal"><span>I couldn’t get it to work with “authMgr = QgsAuthManager.instance()” so following the comment at the top of (</span><a href="https://qgis.org/pyqgis/3.4/core/QgsAuthManager.html" target="_blank">https://qgis.org/pyqgis/3.4/core/QgsAuthManager.html</a><span>)
 I used “authMgr =  QgsApplication.authManager()” instead.<u></u><u></u></span></p>
<p class="MsoNormal"><span><u></u> <u></u></span></p>
<p class="MsoNormal"><span>I changed “authMgr.authenticationDbPath()” to “authMgr.authenticationDatabasePath()”.<u></u><u></u></span></p>
<p class="MsoNormal"><span><u></u> <u></u></span></p>
<p class="MsoNormal"><span>I also changed “QgsDataSourceURI()” to “QgsDataSourceUri()”.<u></u><u></u></span></p>
<p class="MsoNormal"><span><u></u> <u></u></span></p>
<p class="MsoNormal"><span>p_config.setConfig("certpath", "path/to/alice-cert.pem" ))<u></u><u></u></span></p>
<p class="MsoNormal"><span>p_config.setConfig("keypath", "path/to/alice-key.pem" ))<u></u><u></u></span></p>
<p class="MsoNormal"><span>There are extra brackets on the lines above but clearly those are just typos.
<u></u><u></u></span></p>
<p class="MsoNormal"><span><u></u> <u></u></span></p>
<p class="MsoNormal"><span>Finally the line “rlayer = QgsRasterLayer(quri.encodedUri(), 'states', 'wms')” only ran if I put in “rlayer = QgsRasterLayer(str(quri.encodedUri()), 'states', 'wms')”.<u></u><u></u></span></p>
<p class="MsoNormal"><span><u></u> <u></u></span></p>
<p class="MsoNormal"><span>That is the issue though; whilst the line above runs in QGIS it doesn’t appear to actually be authenticating on the GetCapabilities request. This maybe because our server uses pre-authentication
 because it is a GeoServer which is set to HIDE (</span><a href="https://docs.geoserver.org/latest/en/user/security/webadmin/data.html#catalog-mode" target="_blank">https://docs.geoserver.org/latest/en/user/security/webadmin/data.html#catalog-mode</a>)<span>.
<u></u><u></u></span></p>
<p class="MsoNormal"><span><u></u> <u></u></span></p>
<p class="MsoNormal"><span>As far as I can tell there is no concept of that in QGIS so in effect I believe QGIS would not support HIDE mode GeoServers unless you are using some sort of token based authentication as it will
 send a number of requests without the correct authentication settings. I’ve been investigating a work around given that this process is aimed at connections via our network only but perhaps I’ve missed something obvious or the use of str() in the statement
 above is simply preventing the authentication manager from expanding the auth credentials at the last minute?
<u></u><u></u></span></p>
<p class="MsoNormal"><span><u></u> <u></u></span></p>
<p class="MsoNormal"><span>I’ll go do a quick update for the brackets and I can update the other lines once others have confirmed my interpretations are correct; they compiled but that doesn’t mean I got them right!<u></u><u></u></span></p>
<p class="MsoNormal"><span><u></u> <u></u></span></p>
<p class="MsoNormal"><span>Thanks,<u></u><u></u></span></p>
<p class="MsoNormal"><span>Paul<u></u><u></u></span></p>
<p class="MsoNormal"><span><u></u> <u></u></span></p>
<p class="MsoNormal"><span><u></u> <u></u></span></p>
<p class="MsoNormal"><b><span lang="EN-US">From:</span></b><span lang="EN-US"> DelazJ <<a href="mailto:delazj@gmail.com" target="_blank">delazj@gmail.com</a>>
<br>
<b>Sent:</b> 24 July 2019 23:25<br>
<b>To:</b> Paul Wittle <<a href="mailto:P.Wittle@dorsetcc.gov.uk" target="_blank">P.Wittle@dorsetcc.gov.uk</a>><br>
<b>Cc:</b> <a href="mailto:qgis-user@lists.osgeo.org" target="_blank">qgis-user@lists.osgeo.org</a><br>
<b>Subject:</b> Re: [Qgis-user] Using QgsAuthManager<u></u><u></u></span></p>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">Hi,<u></u><u></u></p>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">Le mer. 24 juil. 2019 à 14:20, Paul Wittle <<a href="mailto:paul.wittle@dorsetcouncil.gov.uk" target="_blank">paul.wittle@dorsetcouncil.gov.uk</a>> a écrit :<u></u><u></u></p>
</div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0cm 0cm 0cm 6pt;margin:5pt 0cm 5pt 4.8pt">
<div>
<div>
<p class="MsoNormal">Hi,<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">I’m trying to use python to assign an authentication configuration to a WMS layers that I’m adding. I have been using the following guide
<a href="https://docs.qgis.org/3.4/en/docs/pyqgis_developer_cookbook/authentication.html#leave-authcfg-expansion-to-qgsauthmanager" target="_blank">
https://docs.qgis.org/3.4/en/docs/pyqgis_developer_cookbook/authentication.html#leave-authcfg-expansion-to-qgsauthmanager</a>.<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">I had to update a few bits as I think some of the code maybe a little out of date but I managed to get it all working right down to the section I’ve linked to.<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">The line  “rlayer = QgsRasterLayer(quri.encodedUri(), 'states', 'wms')” was resulting in an unexpected type error as encodedUri returns a QByteArray rather than a string but I just
 wrapped it in str(quri.encodedUri()) and that now returns as a string. <u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal">Paul, can you share all the changes you had to do, so that we can update the docs? Or is the line above the only one you had to change?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">A direct change to the source file (<a href="https://github.com/qgis/QGIS-Documentation/edit/master/source/docs/pyqgis_developer_cookbook/authentication.rst" target="_blank">https://github.com/qgis/QGIS-Documentation/edit/master/source/docs/pyqgis_developer_cookbook/authentication.rst</a>)
 with a pull request for merging would be the most practical way but we'd also welcome changes within a text-like file or in this thread.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Thanks,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Harrissou<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0cm 0cm 0cm 6pt;margin:5pt 0cm 5pt 4.8pt">
<div>
<div>
<p class="MsoNormal">The only trouble is that the getCapabilities statement fails and no layer is added.
<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">Does anyone know how I can see whether the AuthManager attempted to expand the authcfg and send credentials as I suspect it didn’t in my case?<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">Sorry if this email is too much along the developer lines for this mailing list but it is only plugin development rather than actual development of the application itself so I thought
 I’d try my luck.<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">Thanks,<u></u><u></u></p>
<p class="MsoNormal">Paul<u></u><u></u></p>
</div>
<p class="MsoNormal">This e-mail and any files transmitted with it are intended solely for the use of the individual or entity to whom they are addressed. It may contain unclassified but sensitive or protectively marked material and should be handled accordingly.
 Unless you are the named addressee (or authorised to receive it for the addressee) you may not copy or use it, or disclose it to anyone else. If you have received this transmission in error please notify the sender immediately. All traffic may be subject to
 recording and/or monitoring in accordance with relevant legislation. Any views expressed in this message are those of the individual sender, except where the sender specifies and with authority, states them to be the views of Dorset Council. Dorset Council
 does not accept service of documents by fax or other electronic means. Virus checking: Whilst all reasonable steps have been taken to ensure that this electronic communication and its attachments whether encoded, encrypted or otherwise supplied are free from
 computer viruses, Dorset Council accepts no liability in respect of any loss, cost, damage or expense suffered as a result of accessing this message or any of its attachments. For information on how Dorset Council processes your information, please see
<a href="http://www.dorsetcouncil.gov.uk/416433" target="_blank">www.dorsetcouncil.gov.uk/416433</a>
<u></u><u></u></p>
</div>
<p class="MsoNormal">_______________________________________________<br>
Qgis-user mailing list<br>
<a href="mailto:Qgis-user@lists.osgeo.org" target="_blank">Qgis-user@lists.osgeo.org</a><br>
List info: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-user" target="_blank">
https://lists.osgeo.org/mailman/listinfo/qgis-user</a><br>
Unsubscribe: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-user" target="_blank">
https://lists.osgeo.org/mailman/listinfo/qgis-user</a><u></u><u></u></p>
</blockquote>
</div>
</div>
</div>
This e-mail and any files transmitted with it are intended solely for the use of the individual or entity to whom they are addressed. It may contain unclassified but sensitive or protectively marked material and should be handled accordingly. Unless you are
 the named addressee (or authorised to receive it for the addressee) you may not copy or use it, or disclose it to anyone else. If you have received this transmission in error please notify the sender immediately. All traffic may be subject to recording and/or
 monitoring in accordance with relevant legislation. Any views expressed in this message are those of the individual sender, except where the sender specifies and with authority, states them to be the views of Dorset Council. Dorset Council does not accept
 service of documents by fax or other electronic means. Virus checking: Whilst all reasonable steps have been taken to ensure that this electronic communication and its attachments whether encoded, encrypted or otherwise supplied are free from computer viruses,
 Dorset Council accepts no liability in respect of any loss, cost, damage or expense suffered as a result of accessing this message or any of its attachments. For information on how Dorset Council processes your information, please see <a href="http://www.dorsetcouncil.gov.uk/416433" target="_blank">www.dorsetcouncil.gov.uk/416433</a>
</div>

_______________________________________________<br>
Qgis-user mailing list<br>
<a href="mailto:Qgis-user@lists.osgeo.org" target="_blank">Qgis-user@lists.osgeo.org</a><br>
List info: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-user" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-user</a><br>
Unsubscribe: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-user" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-user</a></blockquote></div>