QNetworkAccessManager::authenticationRequired signal not emitted
-
Hi, I posted in a very old thread so figured maybe it's good to start a new one for this specific issue.
I'm using Qt 6.6.0 and a basic example from the Qt core advanced lessons on udemy to connect to a company server using SSL and a GET-request. The server uses NTLM authentication but even though I can see that the server sends this in the header, the authenticationRequired signal is not emitted so I'm not able to handle the authentication. I can see that the SSL-connection seems to work fine (the encrypted slot is called). I have tested the access to the server using postman-agent and it works fine.
When I make a GET-request using the class below and debug the header pairs, I get this:
Reply: QList(std::pair("server","Microsoft-IIS/10.0"), std::pair("www-authenticate","Negotiate, NTLM"), std::pair("x-powered-by","ASP.NET"), std::pair("date","Tue, 06 Feb 2024 12:20:48 GMT")) errors: QNetworkReply::AuthenticationRequiredError
So in my mind the authenticationRequired signal should be emitted, but the slot is not called.
I have tried to find if there is a way to set up the authenitcation in any other way than waiting for this slot to be called, but have not found any.
Any suggestion on what could be wrong or what to check?I have tried QNetworkAccessManager::clearAccessCache() but that did not help.
I'm using this class:
#ifndef NETWORKMANAGER_H #define NETWORKMANAGER_H #include <QObject> #include <QCoreApplication> #include <QNetworkAccessManager> #include <QNetworkRequest> #include <QNetworkReply> #include <QAuthenticator> #include <QDebug> #include <QSslSocket> class networkManager : public QObject { Q_OBJECT public: explicit networkManager(QObject *parent = nullptr); public slots: void requestFinished(QNetworkReply *reply); void authenticationRequired(QNetworkReply *reply, QAuthenticator *authenticator); void makeRequest(QString URL); void preSharedKeyAuthenticationRequired(QNetworkReply *reply, QSslPreSharedKeyAuthenticator *authenticator); void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator); void encrypted(QNetworkReply *reply); void sslErrors(QNetworkReply *reply, const QList<QSslError> &errors); void readyRead(); void connectToHost(QString host, quint16 port); void connected(); private: QNetworkAccessManager *manager; }; #endif // NETWORKMANAGER_H
#include "networkmanager.h" networkManager::networkManager(QObject *parent) : QObject{parent} { manager = new QNetworkAccessManager(this); connect(manager, &QNetworkAccessManager::authenticationRequired, this, &networkManager::authenticationRequired); connect(manager, &QNetworkAccessManager::preSharedKeyAuthenticationRequired,this, &networkManager::preSharedKeyAuthenticationRequired); connect(manager, &QNetworkAccessManager::proxyAuthenticationRequired,this, &networkManager::proxyAuthenticationRequired); connect(manager, &QNetworkAccessManager::finished, this, &networkManager::requestFinished); connect(manager, &QNetworkAccessManager::encrypted, this, &networkManager::encrypted); connect(manager, &QNetworkAccessManager::sslErrors, this, &networkManager::sslErrors); } void networkManager::requestFinished(QNetworkReply *reply) { if (reply->error() == QNetworkReply::NoError) { qInfo() << "Request successful!"; qInfo() << "Response:" << reply->readAll(); } else { qInfo() << "readAll: " << reply->readAll(); qInfo() << "Error:" << reply->errorString(); qInfo() << "Reply:" << reply->rawHeaderPairs(); qInfo() << "errors: " << reply->error(); } } void networkManager::connectToHost(QString host, quint16 port){ qInfo() << "Connecting to host using SSL..."; manager->connectToHostEncrypted(host, port); } void networkManager::connected(){ qInfo() << "Connected!"; } void networkManager::sslErrors(QNetworkReply *reply, const QList<QSslError> &errors) { Q_UNUSED(reply); Q_UNUSED(errors); qInfo() << "sslErrors"; } void networkManager::encrypted(QNetworkReply *reply) { //Q_UNUSED(reply); qInfo() << "encrypted"; if(reply) qInfo() << "Reply: " << reply->readBufferSize(); } void networkManager::preSharedKeyAuthenticationRequired(QNetworkReply *reply, QSslPreSharedKeyAuthenticator *authenticator) { qInfo() << "preSharedKeyAuthenticationRequired"; } void networkManager::proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator) { qInfo() << "proxyAuthenticationRequired"; } void networkManager::authenticationRequired(QNetworkReply *reply, QAuthenticator *authenticator) { // NTLM authentication credentials qInfo() << "authenticationRequired signal emitted!"; } void networkManager::readyRead() { qInfo() << "ReadyRead"; QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender()); if(reply) qInfo() << reply->readAll(); } void networkManager::makeRequest(QString URL) { // Set up the request QNetworkRequest request = QNetworkRequest(QUrl(URL)); QNetworkReply *reply = manager->get(request); connect(reply, &QNetworkReply::readyRead, this, &networkManager::readyRead); }