Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QNetworkAccessManager::authenticationRequired signal not emitted
Forum Updated to NodeBB v4.3 + New Features

QNetworkAccessManager::authenticationRequired signal not emitted

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 456 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Depronized
    wrote on 6 Feb 2024, 13:14 last edited by
    #1

    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);
    }
    
    
    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on 8 Feb 2024, 01:43 last edited by
      #2

      Duplicate here

      D 1 Reply Last reply 8 Feb 2024, 15:29
      0
      • C ChrisW67
        8 Feb 2024, 01:43

        Duplicate here

        D Offline
        D Offline
        Depronized
        wrote on 8 Feb 2024, 15:29 last edited by
        #3

        @ChrisW67 yea, the forum suggested the thread I was writing in before might be too old, so I do not know if it is the right thing to start a new one or keep writing in the old.

        1 Reply Last reply
        0

        2/3

        8 Feb 2024, 01:43

        • Login

        • Login or register to search.
        2 out of 3
        • First post
          2/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved