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. JWT - Post login request via JSON using Qt

JWT - Post login request via JSON using Qt

Scheduled Pinned Locked Moved Solved General and Desktop
jsonaccess tokenqnetworkapipost
6 Posts 3 Posters 1.1k 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.
  • R Offline
    R Offline
    R-P-H
    wrote on last edited by R-P-H
    #1

    Hi, I am trying to post a login request to my Django-rest API framework using Qt v5.15.2 C++. My restful API is using JWT authentication.

    Login is supposed to work by posting the username/password via the JSON body and then receiving the access token back and using that token in the header for all subsequent requests.

    When I attempt to login using Qt I get the error: QNetworkReply::AuthenticationRequiredError "Host requires authentication".

    But for login, no authentication is required ? i.e. it is not possible to have an access token yet if you haven't logged in.

    Any suggestions? Thanks.

    SGaistS 1 Reply Last reply
    0
    • R Offline
      R Offline
      R-P-H
      wrote on last edited by
      #6

      After playing around using postman I found the issue.

      When sending a Bearer: "" or Bearer: "xxxxxx" token, the server returns "Authentication Required".

      But when sending no Bearer token or an empty Bearer: it works fine.

      So when logging in; no token must be supplied else it tries to authenticate against that token instead of correctly generating a new one provided you submitted valid credentials in the JSON body.

      Seems a bit odd to me, but ok.

      1 Reply Last reply
      0
      • R R-P-H

        Hi, I am trying to post a login request to my Django-rest API framework using Qt v5.15.2 C++. My restful API is using JWT authentication.

        Login is supposed to work by posting the username/password via the JSON body and then receiving the access token back and using that token in the header for all subsequent requests.

        When I attempt to login using Qt I get the error: QNetworkReply::AuthenticationRequiredError "Host requires authentication".

        But for login, no authentication is required ? i.e. it is not possible to have an access token yet if you haven't logged in.

        Any suggestions? Thanks.

        SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi,

        Are you sure you are using the token properly after its retrieval ?

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

        R 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          Are you sure you are using the token properly after its retrieval ?

          R Offline
          R Offline
          R-P-H
          wrote on last edited by
          #3

          @SGaist said in JWT - Post login request via JSON using Qt:

          Hi,

          Are you sure you are using the token properly after its retrieval ?

          Hi, I am not able to retrieve the token. I get that authentication required error when trying to login. But the login API endpoint does not require a token.

          SGaistS 1 Reply Last reply
          0
          • H Offline
            H Offline
            Hanson
            wrote on last edited by
            #4

            Have you used postman to test the login API?
            And can you show the code you write.

            “Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.”
            —— Martin Golding

            1 Reply Last reply
            0
            • R R-P-H

              @SGaist said in JWT - Post login request via JSON using Qt:

              Hi,

              Are you sure you are using the token properly after its retrieval ?

              Hi, I am not able to retrieve the token. I get that authentication required error when trying to login. But the login API endpoint does not require a token.

              SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #5

              @R-P-H my bad, it misunderstood your issue. From what I know, your JWT endpoint should in any case require authentication to generate the token. What might happen is that the JSON you are sending is not properly formed. Can you show the code you use for that part ?

              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
              0
              • R Offline
                R Offline
                R-P-H
                wrote on last edited by
                #6

                After playing around using postman I found the issue.

                When sending a Bearer: "" or Bearer: "xxxxxx" token, the server returns "Authentication Required".

                But when sending no Bearer token or an empty Bearer: it works fine.

                So when logging in; no token must be supplied else it tries to authenticate against that token instead of correctly generating a new one provided you submitted valid credentials in the JSON body.

                Seems a bit odd to me, but ok.

                1 Reply Last reply
                0
                • R R-P-H has marked this topic as solved on

                • Login

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