JWT - Post login request via JSON using Qt
-
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.
-
After playing around using postman I found the issue.
When sending a
Bearer: ""
orBearer: "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.
-
@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.
-
@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 ?
-
After playing around using postman I found the issue.
When sending a
Bearer: ""
orBearer: "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.
-