Unsolved Reddit Example failing
-
There's no linking to be done. OpenSSL is dynamically loaded at run time. One thing you can to is to copy the dlls in the same folders as your application.
The other is to modify the PATH environment variable in the Run part of the Project panel and add the folder that contains the dlls to it.
By the way, which compiler are you using ?
-
I'm still seeing this error in the output:
qt.networkauth.oauth2: Unexpected call
But it did succeed authenticating. I'm using Mingw.
OK, so this at least works on Windows. Now to make it work on WSL2/Linux. -
What error are you getting on Linux ?
-
On Linux I'm struggling with the entire process. I can't figure out where the
redirect_uri
is comming from.Because it's not generated from
QOAuthHttpServerReplyHandler
. If I manually change the URL to point to the correct IP i getqt.networkauth.oauth2: Error: invalid_grant
, but I think that is expected. -
The URL is set in your Reddit application configuration on the website.
-
Well, then something is broken in Qt. Because the
redirect_uri
definitely does not match what I set in my Reddit app. -
@HappyCerberus Please note that openSSL redistributed with Qt is for MSVC only. For use with MinGW you'd need to find precompiled binaries build with MinGW, version 1.1.1.4 (or 1.1.1.d), respectively x86 or x64. Or build them yourself.
-
@artwaw So, what you are saying is that the single case that I actually managed to get working is one that should not work :-D This is getting better and better :-)
-
@HappyCerberus It is a bit of a mystery for me too :) But I learned the hard way the first time they included OpenSSL in Qt and since then I don't rely this particular source.
-
@HappyCerberus I've de-dusted my old problems I had with SSL supplied via onlineinstaller - here goes the summary:
- I compile with MinGW on Windows. Always have been.
- once OpenSSL became available I was very happy, since it should simplify things. I began to use it but users reported to me that on some machines it doesn't work.
- I've spent quite some time debugging until I took a look into libraries provided. They're compiled with MSVC so they need MSVC libraries to run. If you have them installed, everything will work just fine. So if it worked, it worked but some of my users have not had those libs installed.
- Since then I stopped using bundled OpenSSL, as it is just potential additional overhead and more dependencies.
So if it worked for you, you simply had those Microsoft runtime libraries installed. But I'd check with dependency free MinGW compiled SSL libs too, just to be sure.
-
@artwaw Yeah, my problem now is that it doesn't work on Linux, and I suspect that it will not work because of the
redirect_uri
. -
@HappyCerberus That's beyond my area of experience, I am afraid. Hopefully more experienced colleagues here can be of help.
-
Do you get the same issue with a "classic" Linux rather than WSL2 ?
-
Yeah, unfortunately the
redirect_uri
is again wrong and when I manually change it I get:qt.networkauth.oauth2: Unexpected call qt.networkauth.oauth2: Error: invalid_grant
-
I was having the same problem.
I had to manually set the
redirect_uri
for theRequestingAuthorization
stage to just get that first part to work.After that I get the same
invalid_grant
error.The reddit api says that you get this error if you use an expired code, or reuse a code. Apparently though, you also get it if the
redirect_uri
s in both theRequestingAuthorization
stage and theRequestingAccessToken
stage don't match.oauth2.setModifyParametersFunction([&](QAbstractOAuth::Stage stage, QVariantMap *parameters) { if(stage == QAbstractOAuth::Stage::RequestingAuthorization) { parameters->insert("duration", "permanent"); parameters->insert("redirect_uri", QByteArray("http://127.0.0.1:1337")); } else if(stage == QAbstractOAuth::Stage::RequestingAccessToken) { parameters->insert("redirect_uri", QByteArray("http://127.0.0.1:1337")); } });
That seems to have worked.