-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a803be7
commit 02a4e55
Showing
3 changed files
with
52 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/*************************************************************************** | ||
qgsauthorizationsettings.cpp | ||
--------------------- | ||
begin : December 2024 | ||
copyright : (C) 2024 by Damiano Lombardi | ||
email : damiano at opengis.ch | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsauthorizationsettings.h" | ||
|
||
QgsAuthorizationSettings::QgsAuthorizationSettings(const QString &userName, const QString &password, const QgsHttpHeaders &httpHeaders, const QString &authcfg) | ||
: mUserName( userName ) | ||
, mPassword( password ) | ||
, mHttpHeaders( httpHeaders ) | ||
, mAuthCfg( authcfg ) | ||
{} | ||
|
||
bool QgsAuthorizationSettings::setAuthorization(QNetworkRequest &request) const | ||
{ | ||
if ( !mAuthCfg.isEmpty() ) // must be non-empty value | ||
{ | ||
return QgsApplication::authManager()->updateNetworkRequest( request, mAuthCfg ); | ||
} | ||
else if ( !mUserName.isEmpty() || !mPassword.isEmpty() ) | ||
{ | ||
request.setRawHeader( "Authorization", "Basic " + QStringLiteral( "%1:%2" ).arg( mUserName, mPassword ).toUtf8().toBase64() ); | ||
} | ||
|
||
mHttpHeaders.updateNetworkRequest( request ); | ||
|
||
return true; | ||
} | ||
|
||
bool QgsAuthorizationSettings::setAuthorizationReply(QNetworkReply *reply) const | ||
{ | ||
if ( !mAuthCfg.isEmpty() ) | ||
{ | ||
return QgsApplication::authManager()->updateNetworkReply( reply, mAuthCfg ); | ||
} | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters