QGIS API Documentation 3.99.0-Master (d270888f95f)
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
18#include "qgslogger.h"
19
20#include <QString>
21
22using namespace Qt::StringLiterals;
23
24QgsAuthorizationSettings::QgsAuthorizationSettings( const QString &userName, const QString &password, const QgsHttpHeaders &httpHeaders, const QString &authcfg )
25 : mUserName( userName )
26 , mPassword( password )
27 , mHttpHeaders( httpHeaders )
28 , mAuthCfg( authcfg )
29{}
30
31bool QgsAuthorizationSettings::setAuthorization( QNetworkRequest &request ) const
32{
33 if ( !mAuthCfg.isEmpty() ) // must be non-empty value
34 {
35#ifdef HAVE_AUTH
37#else
38 QgsDebugError( u"Auth manager is not available - cannot update network request for authcfg: %1"_s.arg( mAuthCfg ) );
39 return false;
40#endif
41 }
42 else if ( !mUserName.isEmpty() || !mPassword.isEmpty() )
43 {
44 request.setRawHeader( "Authorization", "Basic " + u"%1:%2"_s.arg( mUserName, mPassword ).toUtf8().toBase64() );
45 }
46
47 mHttpHeaders.updateNetworkRequest( request );
48
49 return true;
50}
51
52bool QgsAuthorizationSettings::setAuthorizationReply( QNetworkReply *reply ) const
53{
54 if ( !mAuthCfg.isEmpty() )
55 {
57 }
58 return true;
59}
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.
Implements simple HTTP header management.
#define QgsDebugError(str)
Definition qgslogger.h:59