QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
qgsauthorizationsettings.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsauthorizationsettings.cpp
3 ---------------------
4 begin : December 2024
5 copyright : (C) 2024 by Damiano Lombardi
6 email : damiano at opengis.ch
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
17
18QgsAuthorizationSettings::QgsAuthorizationSettings( const QString &userName, const QString &password, const QgsHttpHeaders &httpHeaders, const QString &authcfg )
19 : mUserName( userName )
20 , mPassword( password )
21 , mHttpHeaders( httpHeaders )
22 , mAuthCfg( authcfg )
23{}
24
25bool QgsAuthorizationSettings::setAuthorization( QNetworkRequest &request ) const
26{
27 if ( !mAuthCfg.isEmpty() ) // must be non-empty value
28 {
30 }
31 else if ( !mUserName.isEmpty() || !mPassword.isEmpty() )
32 {
33 request.setRawHeader( "Authorization", "Basic " + QStringLiteral( "%1:%2" ).arg( mUserName, mPassword ).toUtf8().toBase64() );
34 }
35
37
38 return true;
39}
40
41bool QgsAuthorizationSettings::setAuthorizationReply( QNetworkReply *reply ) const
42{
43 if ( !mAuthCfg.isEmpty() )
44 {
46 }
47 return true;
48}
static QgsAuthManager * authManager()
Returns the application's authentication manager instance.
bool updateNetworkRequest(QNetworkRequest &request, const QString &authcfg, const QString &dataprovider=QString())
Provider call to update a QNetworkRequest with an authentication config.
bool updateNetworkReply(QNetworkReply *reply, const QString &authcfg, const QString &dataprovider=QString())
Provider call to update a QNetworkReply with an authentication config (used to skip known SSL errors,...
QString mPassword
Password for basic http authentication.
QgsAuthorizationSettings(const QString &userName=QString(), const QString &password=QString(), const QgsHttpHeaders &httpHeaders=QgsHttpHeaders(), const QString &authcfg=QString())
Constructor for QgsAuthorizationSettings.
QString mAuthCfg
Authentication configuration ID.
bool setAuthorization(QNetworkRequest &request) const
Update authorization for request.
QString mUserName
Username for basic http authentication.
QgsHttpHeaders mHttpHeaders
headers for http requests
bool setAuthorizationReply(QNetworkReply *reply) const
Update authorization for reply.
This class implements simple http header management.
bool updateNetworkRequest(QNetworkRequest &request) const
Updates a request by adding all the HTTP headers.