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
549 stars 159 forks source link

Cors issue only on token validation #224

Open jeanrinvil opened 2 years ago

jeanrinvil commented 2 years ago

I'm using your plugin with my ionic app

When I use the /jwt-auth/v1/token/validate , I got a cors problem However, /jwt-auth/v1/token/ seems to work well

I already put this on my htaccess :

RewriteEngine on
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]

and enable cors in my wp-config :

define('JWT_AUTH_CORS_ENABLE', true);

What I need to check ?

paulando commented 11 months ago

Had the same issue. For me the problem was with setting up headers.

So instead of this:

const response = await fetch(`${wpRestApi}/jwt-auth/v1/token/validate`, {
    headers: {
        'Authorization': `Bearer ${token}`,
    },
    method: "POST",
});

Did this:

const headers = new Headers({
    'Authorization': `Bearer ${token}`,
});

const response = await fetch(`${wpRestApi}/jwt-auth/v1/token/validate`, {
    headers,
    method: "POST",
});