Add parameter to QOAuth2AuthorizationCodeFlow using setModifyParametersFunction
-
wrote on 17 Apr 2025, 14:48 last edited by
I am working on a Qt project. I want to establish permanent access to Reddit API using the
refresh_token
that reddit's OAuth Authentication provides after successful authentication and that Qt'sQOAuth2AuthorizationCodeFlow
does support.The only problem being that Reddit's OAuth requires the parameter
duration
to be set topermanent
as a part of the authentication request in order to receive arefresh_token
.duration
seems to be a non-standard parameter asQOAuth2AuthorizationCodeFlow
does not have a direct way to set the duration.I tried using
setModifyParametersFunction
like 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?
-
wrote 18 days ago last edited by codeIMperfect 5 Jan 2025, 11:26
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 ?
-
wrote 18 days ago last edited by codeIMperfect 5 Jan 2025, 11:26
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!
-
-
-
-