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
558 stars 161 forks source link

Error 401 how fix this #136

Closed guntercn closed 1 year ago

guntercn commented 5 years ago

Hi, I have a problem and I can not figure out how to fix it software Wordpress 5.0.3 JWT 1.2.5 wp-rest api Ionic v3 the file .htaccess has RewriteEngine on RewriteCond %{HTTP:Authorization} ^(.) RewriteRule ^(.) - [E=HTTP_AUTHORIZATION:%1] SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1

the file config define('JWT_AUTH_SECRET_KEY', 'mi-top-secret-key'); define('JWT_AUTH_CORS_ENABLE', true);

Now: 1- login token jwt-auth/v1/token works fine response a user and token 2- Validate token response "jwt_auth_valid_token" 3- in ionic, i send headerSettings['Authorization'] = 'Bearer ' + token; but always response "rest_cannot_view" /wp/v2/users/me requires authentication on this site. this is my proble how fix this.

even... in the server o got wp/v2/users/me GET REST API HTTP 401 Unauthorized

Headers Authorization | Bearer eyJ0eXAiOiJKV1Qi.........

$_SERVER HTTP_AUTHORIZATION Bearer eyJ0eXAiOi...

but always reponse error 401, thanks por your help

madebycaliper commented 5 years ago

It seems that there's some sort of error being caused by the upgrade to JWT v1.2.5. I've spent about a week trying to figure out why my requests were working in Postman and not in the browser, and it has to do with updating. I'd suggest rolling back to JWT v.1.2.4 until @Tmeister merges a PR that fixes it

LucasNevesAraujo commented 5 years ago

I'm having the same problem. Any request works on PHP wp_remote_get and cUrl, but not on JS or Postman. I figure it out that I was sending the wordpress_logged_in_% cookie on every request, even on Postman. This seems to be the problem, but it was working on an early version.

LucasNevesAraujo commented 5 years ago

I'm not the only one :) #133