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. QNetworkAuthorization and Microsoft Graph
QtWS25 Last Chance

QNetworkAuthorization and Microsoft Graph

Scheduled Pinned Locked Moved Solved General and Desktop
networkauthmicrosoftmicrosoft graphoauth2.0
10 Posts 2 Posters 1.1k 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.
  • LorenDBL Offline
    LorenDBL Offline
    LorenDB
    wrote on last edited by
    #1

    I'm building a class to access the Microsoft Graph APIs. However, I can't get the authentication to finish the way it's supposed to (according to the Reddit example).

    I've uploaded the basic code for this example to GitHub.

    Ideally, once the authorization flow in the code completes, I should have the authorized signal emitted. However, that's not happening. Could somebody enlighten me as to why?

    If you need system information, I'm on openSUSE Tumbleweed building against the latest Qt 6.3. If you need more details, ask away and I'll be happy to get you all the information you need.

    1 Reply Last reply
    0
    • LorenDBL Offline
      LorenDBL Offline
      LorenDB
      wrote on last edited by
      #9

      I found my problem. I was calling setState() on my OAuth object, because, after all, you are permitted to do that and every website I saw said that sending a state with the OAuth request was a good idea. Well, when I removed the setState call, I immediately got authentication in Qt.

      ¯\_(ツ)_/¯

      I'd assume that Qt would at least document things like that. If they are going to provide a way to set a custom state, they should make it work or tell you that it doesn't work. Oh well.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi,

        You are only testing a single state, you should also check the others, that might give you a clue about what is going on.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        LorenDBL 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          You are only testing a single state, you should also check the others, that might give you a clue about what is going on.

          LorenDBL Offline
          LorenDBL Offline
          LorenDB
          wrote on last edited by
          #3

          @SGaist I removed the debug lines that I had entered in my actual app. The stage handler only fires once (for QAbstractOAuth::Stage::RequestingAuthorization) and the status handler never fires.

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #4

            In that case, I would use one of the constructor where you can specify the QNetworkAccessManager to use and connect its error signals to see if something goes wrong there.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • LorenDBL Offline
              LorenDBL Offline
              LorenDB
              wrote on last edited by
              #5

              Having connected log lambdas to the QNetworkAccessManager's signals, it appears that the QNetworkAccessManager is never used. With that being said, I also added this code to catch my QOAuthHttpServerReplyHandler's signals:

                  connect(handler, &QOAuthHttpServerReplyHandler::callbackReceived, this, [this](const QVariantMap &v) {
                      std::cout << "got callback: " << v.firstKey().toStdString() << " is first" << std::endl;
                  });
                  connect(handler, &QOAuthHttpServerReplyHandler::callbackDataReceived, this, [](const QByteArray &b) {
                      std::cout << "got callback data: " << b.toStdString() << std::endl;
                  });
                  connect(handler, &QOAuthHttpServerReplyHandler::replyDataReceived, this, [](const QByteArray &b) {
                      std::cout << "got reply data: " << b.toStdString() << std::endl;
                  });
                  connect(handler, &QOAuthHttpServerReplyHandler::tokensReceived, this, [this](const QVariantMap &v) {
                      std::cout << "got tokens: " << v.firstKey().toStdString() << " is first" << std::endl;
                  });
              

              and found that the only one that is firing is callbackReceived(). The rest of the signals remain silent.

              1 Reply Last reply
              0
              • LorenDBL Offline
                LorenDBL Offline
                LorenDB
                wrote on last edited by LorenDB
                #6

                I also just tested with the Spotify example shown here and confirmed that the Spotify OAuth example works, so it must be a problem with communicating with Graph itself, not with Qt Network Auth as a whole.

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #7

                  I recall (but it's a far far memory) someone had issues with another Microsoft service because they where expecting an additional field or something a bit different.

                  It might be something like described here.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • LorenDBL Offline
                    LorenDBL Offline
                    LorenDB
                    wrote on last edited by
                    #8

                    I don't think that's the problem. As far as I can tell, Graph completely authenticates (it successfully redirects to a URL containing an authentication token in the browser, which should be picked up by the QOAuthHttpServerReplyHandler); the problem is simply that Qt never emits any signals or otherwise carries on with authentication.

                    1 Reply Last reply
                    0
                    • LorenDBL Offline
                      LorenDBL Offline
                      LorenDB
                      wrote on last edited by
                      #9

                      I found my problem. I was calling setState() on my OAuth object, because, after all, you are permitted to do that and every website I saw said that sending a state with the OAuth request was a good idea. Well, when I removed the setState call, I immediately got authentication in Qt.

                      ¯\_(ツ)_/¯

                      I'd assume that Qt would at least document things like that. If they are going to provide a way to set a custom state, they should make it work or tell you that it doesn't work. Oh well.

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #10

                        Nice !

                        You can open a ticket on the bug report system to make an update to the documentation.

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        0

                        • Login

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