QNetworkAuthorization and Microsoft Graph
-
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.
-
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.
-
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.
-
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.
-
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. -
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.
-
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.
-
Nice !
You can open a ticket on the bug report system to make an update to the documentation.