1

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's QOAuth2AuthorizationCodeFlow does support.

The only problem being that Reddit's OAuth requires the parameter duration to be set to permanent as a part of the authentication request in order to receive a refresh_token. duration seems to be a non-standard parameter as QOAuth2AuthorizationCodeFlow does not have a direct way to set the duration.

I tried using setModifyParametersFunction like so but it did not work

QOAuth2AuthorizationCodeFlow 
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?

asked Apr 17, 2025 at 7:58

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.