Add parameter to QOAuth2AuthorizationCodeFlow using setModifyParametersFunction
-
I am working on a Qt project. I want to establish permanent access to Reddit API using the
refresh_tokenthat reddit's OAuth Authentication provides after successful authentication and that Qt'sQOAuth2AuthorizationCodeFlowdoes support.The only problem being that Reddit's OAuth requires the parameter
durationto be set topermanentas a part of the authentication request in order to receive arefresh_token.durationseems to be a non-standard parameter asQOAuth2AuthorizationCodeFlowdoes not have a direct way to set the duration.I tried using
setModifyParametersFunctionlike so but it did not workQOAuth2AuthorizationCodeFlow auto replyHandler = new QOAuthHttpServerReplyHandler(QHostAddress::Any, 1337, this); oauth2.setReplyHandler(replyHandler); oauth2.setAuthorizationUrl(QUrl(authorizationUrl)); oauth2.setTokenUrl(QUrl(accessTokenUrl)); oauth2.setClientIdentifier(clientId); const QSet<QByteArray> scope = {QByteArray("identity"), QByteArray("read")}; oauth2.setRequestedScopeTokens(scope); // Tried to add it here oauth2.setModifyParametersFunction([](QAbstractOAuth::Stage stage, QMultiMap<QString, QVariant> *parameters) { if (!parameters) return; // Abort if pointer is invalid if (stage == QAbstractOAuth::Stage::RequestingAccessToken) { parameters->insert("duration"_L1, "permanent"_L1); } });Can somebody explain why this did not work? Is this an issue at the reddit side or did I just use the function incorrectly?
-
I'm sorry for not replying for so long...
The lambda was getting triggered, and as you pointed out, the stage I was checking for was wrong. I needed to modify them at
QAbstractOAuth::Stage::RequestingAuthorization, not atQAbstractOAuth::Stage::RequestingAccessToken.Anyways, thanks for the quick reply!
-
Hi and welcome to devnet,
Might be a silly question but are you sure your lambda is called ? If so, is it called for all the expected stages ?
-
I'm sorry for not replying for so long...
The lambda was getting triggered, and as you pointed out, the stage I was checking for was wrong. I needed to modify them at
QAbstractOAuth::Stage::RequestingAuthorization, not atQAbstractOAuth::Stage::RequestingAccessToken.Anyways, thanks for the quick reply!
-
C codeIMperfect has marked this topic as solved on
-
C codeIMperfect has marked this topic as solved on
-
C codeIMperfect has marked this topic as solved on
-
C codeIMperfect has marked this topic as solved on