Tmeister / wp-api-jwt-auth

A simple plugin to add JSON Web Token (JWT) Authentication to WP REST API
GNU General Public License v2.0
560 stars 161 forks source link

401 Authorization Required #307

Open Kuro091 opened 2 months ago

Kuro091 commented 2 months ago

Issue Name

Prerequisites

Please answer the following questions for yourself before submitting an issue.

Context

I ran through all the setups procedures. I can see wp-json/jwt-auth/v1/ being added and can see them through GET.

However when I try to POST to wp-json/jwt-auth/v1/token, with username and password being in form data it results in 401 Authorization Required.

Any ideas how to debug this/what caused this?

urlund commented 1 month ago

@Kuro091 use JSON body:

{
  "username": "your_username",
  "password": "your_password"
}
curl --request POST \
  --url http://example.com/wp-json/jwt-auth/v1/token \
  --header 'Content-Type: application/json' \
  --data '{"username": "your_username", "password": "your_password"}'
colombinis commented 3 weeks ago

@Kuro091 I've just tried in my local project with postman and from comand line (exported from postman) it worked in both.

curl --location 'http://local.example.com/wp-json/jwt-auth/v1/token' \
--header 'Content-Type: application/json' \
--data '{
    "username":"Sebastian",
    "password":"password"
}'

{"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOi8vbG9jYWwucGFzc3RoZWtleXMuY29tIiwiaWF0IjoxNzMwODIwNjY0LCJuYmYiOjE3MzA4MjA2NjQsImV4cCI6MTczMTQyNTQ2NCwiZGF0YSI6eyJ1c2VyIjp7ImlkIjoiNTcifX19.hYKmQrJXm0jB8cmgQbHZEfuGfOo5JtShdyrUwtPQhZk","user_email":"sebastian@email.com","user_nicename":"sebastian","user_display_name":"Sebastian"}