Support » Plugin: API Bearer Auth » API whitelist problem

  • Resolved diashima

    (@diashima)


    Hello! I successfully added endpoint ‘/wp-json/wp/v2/posts’ to whitelist, but I still can’t open particular post.
    My question is – what endpoint I must write to make available without authorization every post? Something like: ‘/wp-json/wp/v2/posts/{ID}’
    Putting * in place of {ID} is not working.

    add_filter('api_bearer_auth_unauthenticated_urls', 'api_bearer_auth_unauthenticated_urls_filter', 10, 2);
    function api_bearer_auth_unauthenticated_urls_filter($custom_urls, $request_method) {
      switch ($request_method) {
        case 'POST':
          $custom_urls[] = '/wp-json/wp/v2/users/register';
          break;
        case 'GET':
          $custom_urls[] = '/wp-json/wp/v2/posts';
          break;
      }
      return $custom_urls;
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter diashima

    (@diashima)

    And how i can put two endpoints for GET to whitelist?

    Plugin Author michielve

    (@michielve)

    Hi,

    You have to use regular expressions, so for posts it will be:

    /wp-json/wp/v2/posts/[\d]+

    To add 2 or more endpoints, just add them, for example:

    $custom_urls[] = ‘/wp-json/wp/v2/posts’;
    $custom_urls[] = ‘/wp-json/wp/v2/pages’;
    $custom_urls[] = ‘/wp-json/wp/v2/posts/[\d]+’;

    Best wishes,
    Michiel

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘API whitelist problem’ is closed to new replies.