jonathan-dejong / simple-jwt-authentication

Extends the WP REST API using JSON Web Tokens Authentication as an authentication method.
GNU General Public License v3.0
87 stars 25 forks source link

Fix for the following warning: "Notice: Function register_rest_route was called incorrectly...." #72

Open iamanthonyg opened 1 year ago

iamanthonyg commented 1 year ago

Hi, I noticed that when I install and access the plugin, it shows the following warning:

Notice: Function register_rest_route was called incorrectly. The REST API route definition for simple-jwt-authentication/v1/token is missing the required permission_callback argument. For REST API routes that are intended to be public, use __return_true as the permission callback. Please see Debugging in WordPress for more information. (This message was added in version 5.5.0.) in C:\wamp\www\woo2\wp-includes\functions.php on line 5865

I have also figured out the solution for this. The solution is to add 'permission_callback' => '__return_true', argument. Following is the complete solution to be implemented in the following file: wp-content/plugins/simple-jwt-authentication-master/includes/class-simple-jwt-authentication-rest.php

/**
     * Add the endpoints to the API
     */
    public function add_api_routes() {
        register_rest_route(
            $this->namespace,
            'token',
            array(
                'methods'  => 'POST',
                'callback' => array( $this, 'generate_token' ),
                'permission_callback' => '__return_true',
            )
        );

        register_rest_route(
            $this->namespace,
            'token/validate',
            array(
                'methods'  => 'POST',
                'callback' => array( $this, 'validate_token' ),
                'permission_callback' => '__return_true',
            )
        );

        register_rest_route(
            $this->namespace,
            'token/refresh',
            array(
                'methods'  => 'POST',
                'callback' => array( $this, 'refresh_token' ),
                'permission_callback' => '__return_true',
            )
        );

        register_rest_route(
            $this->namespace,
            'token/revoke',
            array(
                'methods'  => 'POST',
                'callback' => array( $this, 'revoke_token' ),
                'permission_callback' => '__return_true',
            )
        );

        register_rest_route(
            $this->namespace,
            'token/resetpassword',
            array(
                'methods'  => 'POST',
                'callback' => array( $this, 'reset_password' ),
                'permission_callback' => '__return_true',
            )
        );
    }

I hope you will be able to add the above fix in your next update.

Thank you.