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. How do I add a custom header to an already authorized QAbstractOAuth2 object?
Forum Updated to NodeBB v4.3 + New Features

How do I add a custom header to an already authorized QAbstractOAuth2 object?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 412 Views 1 Watching
  • 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.
  • AlveinA Offline
    AlveinA Offline
    Alvein
    wrote on last edited by
    #1

    Hello,

    After being authorized, I'm using the object to make requests:
    QAbstractOAuth2::get(), QAbstractOAuth2::put(), etc.

    How to add headers to the requests made by these functions?

    Just like the function setUserAgent(), which works anytime, is there something for custom headers?

    Thanks.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Essentially a wild guess but I think prepareRequest might be what you are looking for.

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

      AlveinA 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        Essentially a wild guess but I think prepareRequest might be what you are looking for.

        AlveinA Offline
        AlveinA Offline
        Alvein
        wrote on last edited by
        #3

        @SGaist Thanks. =)

        That basically worked this way:

        QOAuth2AuthorizationCodeFlow *oaFlow;
        // ... *oaFlow gets authorized ...
        QNetworkRequest nrqRequest(QUrl("https://somesite.com/someres/somecmd?someparam"));
        // I don't know what the verb/body parameters are good for:
        oaFlow->prepareRequest(&nrqRequest,QByteArray(),QByteArray());
        nrqRequest.setRawHeader("X-SOMETHING","blah");
        QNetworkReply *nrpReply=oaFlow->networkAccessManager()->get(nrqRequest);
        

        I don't like having to create a QNetworkRequest myself, but for a one-time use, it's fine.

        Also, at this point I already had created a custom QNetworkAccessManager re-implementing createRequest() and including some methods to add/remove raw headers. And then used QAbstractOAuth::setNetworkAccessManager() to link it to the authorized object.

        1 Reply Last reply
        0

        • Login

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