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
556 stars 160 forks source link

WP Engine doesnt support using htaccess file #290

Open Garcia-Julz opened 11 months ago

Garcia-Julz commented 11 months ago

WP Engine and .htaccess File Compatibility

Using JWT Authentication Plugin with WP Engine Hosting

Before submitting an issue, please answer the following questions:

Context

WP Engine has informed me that they do not support the use of the .htaccess file, even if we were to edit it. Complying with their new standards is essential. Instead of using the code snippet provided in the documentation, WP Engine recommends using a Web Rule or Nginx code snippet to ensure the proper functioning of this plugin.

I attempted to convert the provided .htaccess code into Nginx syntax, but I encountered issues, which is why I'm seeking assistance.

Original .htaccess Code:

SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1

Attempted Nginx Configuration:

location / {
    fastcgi_pass   backend;
    fastcgi_param  HTTP_AUTHORIZATION $http_authorization;
    # Other fastcgi_params and configurations
}

Update

Made another attempt to get around this issue. I added this to my function.php

// Enable JWT authentication
add_filter('jwt_auth_cors_allow_headers', function($headers) {
    $headers[] = 'Authorization';
    return $headers;
}, 10, 1);

add_filter('jwt_auth_secret_key', function($key) {
    // Replace 'YOUR_SECRET_KEY_HERE' with your actual secret key
    $key = 'YOUR_SECRET_KEY_HERE';
    return $key;
}, 10, 1);

just tried this with WP Engine and it did NOT work

location / {
    # Your existing Nginx configuration here

    # JWT authentication
    auth_jwt "[Key I Generated]"; // Use the JWT secret key you defined in functions.php
    auth_jwt_key_file /dev/null; // Use /dev/null to indicate no key file is used
    auth_jwt_alg HS256;

    # Continue with your existing Nginx configuration
}
jared-leddy commented 1 month ago

Flywheel, owned by WP Engine, uses NGINX servers and Google Cloud. We have websites that are hosted on Flywheel that currently use this plugin with no issues.