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?