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. authenticationRequired signal not emited or slot not called

authenticationRequired signal not emited or slot not called

Scheduled Pinned Locked Moved Unsolved General and Desktop
authenticationrestserverphp
9 Posts 5 Posters 2.7k 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.
  • G Offline
    G Offline
    gollum
    wrote on 30 Jun 2016, 10:44 last edited by
    #1

    Hallo there,

    I am having a strange behavior with QNetworkAccessManager. I am getting a QNetworkReply::NetworkError(AuthenticationRequiredError) but the authenticationRequired signal seems not getting emited. The Server is throwing a 401. Any ideas what is wrong?

    I am calling it like:

        manager->get(request);
        connect(manager, SIGNAL(finished(QNetworkReply*)),this, SLOT(replyFinished(QNetworkReply*)));
        connect(manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)),this, SLOT(auth(QNetworkReply*,QAuthenticator*)));
    
    R 1 Reply Last reply 30 Jun 2016, 10:48
    0
    • G gollum
      30 Jun 2016, 10:44

      Hallo there,

      I am having a strange behavior with QNetworkAccessManager. I am getting a QNetworkReply::NetworkError(AuthenticationRequiredError) but the authenticationRequired signal seems not getting emited. The Server is throwing a 401. Any ideas what is wrong?

      I am calling it like:

          manager->get(request);
          connect(manager, SIGNAL(finished(QNetworkReply*)),this, SLOT(replyFinished(QNetworkReply*)));
          connect(manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)),this, SLOT(auth(QNetworkReply*,QAuthenticator*)));
      
      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 30 Jun 2016, 10:48 last edited by
      #2

      @gollum
      IIRC the authenticationRequired signal will be emitted when the HTTP response contains a WWW-Authenticate header.
      HTTP401 is just an error code that you are not allowed to view this resource. So the webserver/webapplication doesn't even ask you to authenticate.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      D 1 Reply Last reply 29 Jan 2024, 10:10
      2
      • R raven-worx
        30 Jun 2016, 10:48

        @gollum
        IIRC the authenticationRequired signal will be emitted when the HTTP response contains a WWW-Authenticate header.
        HTTP401 is just an error code that you are not allowed to view this resource. So the webserver/webapplication doesn't even ask you to authenticate.

        D Offline
        D Offline
        Depronized
        wrote on 29 Jan 2024, 10:10 last edited by
        #3

        @raven-worx I have the same problem in Qt 6.6.1 that the authenticationRequired signal is not emitted.

        When I debug the header sent from the server, I see that it indeed contains a www-authenticate response:

        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","Mon, 29 Jan 2024 08:58:41 GMT"))
        

        So in my understanding this should trigger the signal. Here is my code:

        NTLMexample::NTLMexample(QObject *parent) : QObject{parent}
        {
            connect(&manager, &QNetworkAccessManager::authenticationRequired, this, &NTLMexample::authenticationRequired);
            connect(&manager, &QNetworkAccessManager::preSharedKeyAuthenticationRequired,this, &NTLMexample::preSharedKeyAuthenticationRequired);
            connect(&manager, &QNetworkAccessManager::proxyAuthenticationRequired,this, &NTLMexample::proxyAuthenticationRequired);
            connect(&manager, &QNetworkAccessManager::finished, this, &NTLMexample::requestFinished);
        
        }
        
        void NTLMexample::requestFinished(QNetworkReply *reply)
        {
            if (reply->error() == QNetworkReply::NoError) {
                qInfo() << "Request successful!";
                qInfo() << "Response:" << reply->readAll();
            } else {
                qInfo() << "Error:" << reply->errorString();
                qInfo() << "Reply:" << reply->rawHeaderPairs();
            }
        
        }
        
        void NTLMexample::preSharedKeyAuthenticationRequired(QNetworkReply *reply, QSslPreSharedKeyAuthenticator *authenticator)
        {
            qInfo() << "preSharedKeyAuthenticationRequired";
        }
        
        void NTLMexample::proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator)
        {
            qInfo() << "proxyAuthenticationRequired";
        }
        
        
        void NTLMexample::authenticationRequired(QNetworkReply *reply, QAuthenticator *authenticator)
        {
            // NTLM authentication credentials
            qInfo() << "authenticationRequired signal emitted!";
        
        }
        
        void NTLMexample::makeRequest(QString URL)
        {
            // Set up the request
            QNetworkRequest request = QNetworkRequest(QUrl(URL));
        
            // Make the request
            QNetworkReply *reply = manager.get(request);
        }
        
        C 1 Reply Last reply 31 Jan 2024, 01:36
        0
        • D Depronized
          29 Jan 2024, 10:10

          @raven-worx I have the same problem in Qt 6.6.1 that the authenticationRequired signal is not emitted.

          When I debug the header sent from the server, I see that it indeed contains a www-authenticate response:

          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","Mon, 29 Jan 2024 08:58:41 GMT"))
          

          So in my understanding this should trigger the signal. Here is my code:

          NTLMexample::NTLMexample(QObject *parent) : QObject{parent}
          {
              connect(&manager, &QNetworkAccessManager::authenticationRequired, this, &NTLMexample::authenticationRequired);
              connect(&manager, &QNetworkAccessManager::preSharedKeyAuthenticationRequired,this, &NTLMexample::preSharedKeyAuthenticationRequired);
              connect(&manager, &QNetworkAccessManager::proxyAuthenticationRequired,this, &NTLMexample::proxyAuthenticationRequired);
              connect(&manager, &QNetworkAccessManager::finished, this, &NTLMexample::requestFinished);
          
          }
          
          void NTLMexample::requestFinished(QNetworkReply *reply)
          {
              if (reply->error() == QNetworkReply::NoError) {
                  qInfo() << "Request successful!";
                  qInfo() << "Response:" << reply->readAll();
              } else {
                  qInfo() << "Error:" << reply->errorString();
                  qInfo() << "Reply:" << reply->rawHeaderPairs();
              }
          
          }
          
          void NTLMexample::preSharedKeyAuthenticationRequired(QNetworkReply *reply, QSslPreSharedKeyAuthenticator *authenticator)
          {
              qInfo() << "preSharedKeyAuthenticationRequired";
          }
          
          void NTLMexample::proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator)
          {
              qInfo() << "proxyAuthenticationRequired";
          }
          
          
          void NTLMexample::authenticationRequired(QNetworkReply *reply, QAuthenticator *authenticator)
          {
              // NTLM authentication credentials
              qInfo() << "authenticationRequired signal emitted!";
          
          }
          
          void NTLMexample::makeRequest(QString URL)
          {
              // Set up the request
              QNetworkRequest request = QNetworkRequest(QUrl(URL));
          
              // Make the request
              QNetworkReply *reply = manager.get(request);
          }
          
          C Offline
          C Offline
          ChrisW67
          wrote on 31 Jan 2024, 01:36 last edited by
          #4

          @Depronized Resuscitating an 8-year-old thread for a new problem: not quite a record.

          What is the scope of the manager object?

          D 1 Reply Last reply 31 Jan 2024, 08:02
          0
          • C ChrisW67
            31 Jan 2024, 01:36

            @Depronized Resuscitating an 8-year-old thread for a new problem: not quite a record.

            What is the scope of the manager object?

            D Offline
            D Offline
            Depronized
            wrote on 31 Jan 2024, 08:02 last edited by Depronized
            #5

            @ChrisW67 Yes maybe I should have started a new thread, but since the problme description was the exact same and this wasn't answered, I figured it was better to continue it. Anyway, my manager object is declared in the header file of this class.

            #ifndef NTLMEXAMPLE_H
            #define NTLMEXAMPLE_H
            
            #include <QObject>
            #include <QCoreApplication>
            #include <QNetworkAccessManager>
            #include <QNetworkRequest>
            #include <QNetworkReply>
            #include <QAuthenticator>
            #include <QDebug>
            
            class NTLMexample : public QObject
            {
                Q_OBJECT
            
            public:
                explicit NTLMexample(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);
            
            
            
            private:
                QNetworkAccessManager manager;
            
            };
            
            
            C 1 Reply Last reply 31 Jan 2024, 11:57
            0
            • D Depronized
              31 Jan 2024, 08:02

              @ChrisW67 Yes maybe I should have started a new thread, but since the problme description was the exact same and this wasn't answered, I figured it was better to continue it. Anyway, my manager object is declared in the header file of this class.

              #ifndef NTLMEXAMPLE_H
              #define NTLMEXAMPLE_H
              
              #include <QObject>
              #include <QCoreApplication>
              #include <QNetworkAccessManager>
              #include <QNetworkRequest>
              #include <QNetworkReply>
              #include <QAuthenticator>
              #include <QDebug>
              
              class NTLMexample : public QObject
              {
                  Q_OBJECT
              
              public:
                  explicit NTLMexample(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);
              
              
              
              private:
                  QNetworkAccessManager manager;
              
              };
              
              
              C Offline
              C Offline
              ChrisW67
              wrote on 31 Jan 2024, 11:57 last edited by
              #6

              @Depronized

              Are you you using an instance of this class to process the request?
              Is that object staying in scope for the life of the request and response?
              Exactly what qDebug() output do you see processing the request?
              Do the encrypted() or sslErrors() signals get emitted?

              What client platform?
              Public site?

              D 1 Reply Last reply 31 Jan 2024, 12:58
              0
              • C ChrisW67
                31 Jan 2024, 11:57

                @Depronized

                Are you you using an instance of this class to process the request?
                Is that object staying in scope for the life of the request and response?
                Exactly what qDebug() output do you see processing the request?
                Do the encrypted() or sslErrors() signals get emitted?

                What client platform?
                Public site?

                D Offline
                D Offline
                Depronized
                wrote on 31 Jan 2024, 12:58 last edited by
                #7

                @ChrisW67 Huge thanks for taking your time. Yes I create one instance and call makeRequest with an URL.

                I have verified the URL so I know that it is correct. The server is on our corporate network and my machine is logged in to the domain which is required in order to access this server. I used the Postman Agent to be able to test it, there I chose NTLM authentication and the credentials and it worked fine.

                When I try the same URL in Qt, the only signals that are emitted are finished and encrypted. There is no sslError. Debugging reply->readAll returns empty, but rawHeaderPairs return the result you see in my first post in this thread. That was how I figured out that the server actually sends a www-authentication request because first I assumed it didn't, as the first answer in this thread suggested

                JonBJ 1 Reply Last reply 31 Jan 2024, 13:11
                0
                • D Depronized
                  31 Jan 2024, 12:58

                  @ChrisW67 Huge thanks for taking your time. Yes I create one instance and call makeRequest with an URL.

                  I have verified the URL so I know that it is correct. The server is on our corporate network and my machine is logged in to the domain which is required in order to access this server. I used the Postman Agent to be able to test it, there I chose NTLM authentication and the credentials and it worked fine.

                  When I try the same URL in Qt, the only signals that are emitted are finished and encrypted. There is no sslError. Debugging reply->readAll returns empty, but rawHeaderPairs return the result you see in my first post in this thread. That was how I figured out that the server actually sends a www-authentication request because first I assumed it didn't, as the first answer in this thread suggested

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on 31 Jan 2024, 13:11 last edited by
                  #8

                  @Depronized
                  Perhaps not helpful/does not apply to you, but please read the "box-outs" in https://doc.qt.io/qt-6/qnetworkaccessmanager.html#authenticationRequired (and maybe https://doc.qt.io/qt-6/qnetworkaccessmanager.html#proxyAuthenticationRequired too) carefully. Any chance it worked first time and is cached? Are you using threads/queued connections? Does you finished() signal return the AuthenticationRequiredError error? Does it matter whether you set username/password or not? Just some things for you to check.

                  D 1 Reply Last reply 31 Jan 2024, 14:12
                  0
                  • JonBJ JonB
                    31 Jan 2024, 13:11

                    @Depronized
                    Perhaps not helpful/does not apply to you, but please read the "box-outs" in https://doc.qt.io/qt-6/qnetworkaccessmanager.html#authenticationRequired (and maybe https://doc.qt.io/qt-6/qnetworkaccessmanager.html#proxyAuthenticationRequired too) carefully. Any chance it worked first time and is cached? Are you using threads/queued connections? Does you finished() signal return the AuthenticationRequiredError error? Does it matter whether you set username/password or not? Just some things for you to check.

                    D Offline
                    D Offline
                    Depronized
                    wrote on 31 Jan 2024, 14:12 last edited by
                    #9

                    @JonB I also thought it could be due to cache, so I ran the manager.clearConnectionCache command but that does not help.

                    I also tried to find a way to force it to provide credentials but I have not found any other way to do so. But that was when I still wasn't sure that the server actually requests this, but since I now know that the server sends the www-authenticate request I know the error is in my applicaton or in qt.

                    Yes, I get the QNetworkReply::AuthenticationRequiredError. So weird that I get that error and not the authenticationRequired signal.

                    1 Reply Last reply
                    0
                    • C ChrisW67 referenced this topic on 8 Feb 2024, 01:43

                    • Login

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