Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Add parameter to QOAuth2AuthorizationCodeFlow using setModifyParametersFunction

Add parameter to QOAuth2AuthorizationCodeFlow using setModifyParametersFunction

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 72 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    codeIMperfect
    wrote on 17 Apr 2025, 14:48 last edited by
    #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 or did I just use the function incorrectly?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      codeIMperfect
      wrote 18 days ago last edited by codeIMperfect 5 Jan 2025, 11:26
      #3

      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 at QAbstractOAuth::Stage::RequestingAccessToken.

      Anyways, thanks for the quick reply!

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 17 Apr 2025, 19:06 last edited by
        #2

        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 ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1
        • C Offline
          C Offline
          codeIMperfect
          wrote 18 days ago last edited by codeIMperfect 5 Jan 2025, 11:26
          #3

          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 at QAbstractOAuth::Stage::RequestingAccessToken.

          Anyways, thanks for the quick reply!

          1 Reply Last reply
          0
          • C codeIMperfect has marked this topic as solved 18 days ago
          • C codeIMperfect has marked this topic as solved 18 days ago
          • C codeIMperfect has marked this topic as solved 18 days ago
          • C codeIMperfect has marked this topic as solved 18 days ago

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved