airesvsg / acf-to-rest-api

Exposes Advanced Custom Fields Endpoints in the WordPress REST API
https://wordpress.org/plugins/acf-to-rest-api/
1.33k stars 111 forks source link

When using JWT Auth, v2 works. But v3 responds even without Authentication :( #368

Open easaw opened 3 years ago

easaw commented 3 years ago

As the title indicates, v2 is protected, v3 is not.

When I access; /acf/v2/room/123 I get denied if I don't Authenticate.

But when I access; /acf/v3/room/123 I get a full response even without Authentication.

Is there a fix for this?

Please note, I have this as an mu-plugin:

add_filter( 'rest_authentication_errors', function( $result ) {
if ( true === $result || is_wp_error( $result ) ) {
        return $result;
    }
global $wp;
if ( ! is_user_logged_in() && $wp->request !== 'wp-json/aam/v2/authenticate' ) {
    return new WP_Error(
        'rest_no_auth',
        __( 'Not Authorised' ),
        array( 'status' => 401 )
    );
}
    return $result;
});

Thank you