Skip to content
This repository has been archived by the owner on Nov 14, 2022. It is now read-only.

Add a filter to disable the application password authentication #100

Open
kasparsd opened this issue Feb 21, 2020 · 3 comments
Open

Add a filter to disable the application password authentication #100

kasparsd opened this issue Feb 21, 2020 · 3 comments

Comments

@kasparsd
Copy link
Collaborator

See https://wordpress.org/support/topic/limit-application-to-specific-rest-endpoints/

@styledev
Copy link

styledev commented Mar 4, 2020

Any word on this, is there a way we can manually check for this on our custom endpoints?

@georgestephanis
Copy link
Collaborator

Just worth noting that on the core proposal, the wp_is_application_passwords_available filter is available -- it isn't itself specific to endpoints, as the authentication mechanism can also work with xmlrpc requests and is more agnostic than specific to a specific api implementation, but an earlier action could check the path and disable it if desired.

@davidmpurdy
Copy link

Here's what I came up with to bypass application passwords on a specific endpoint to allow for custom authentication.

function bypass_application_passwords_for_webhook ($available) {

  // if we can't get the current request URL, return default
  global $wp;
  if ( ! is_object ($wp) || empty ($wp->request)) {
    return $available;
  }

  // the path of the current request
  $current_path = trim ($wp->request, '/');

  // the webhook path (which we want to bypass application passwords)
  $webhook_url = \rest_url (REST_NAMESPACE . REST_ROUTE);
  $webhook_path = trim (parse_url ($webhook_url, PHP_URL_PATH), '/');
  
  // if the current path is the webhook path, bypass application password authentication 
  if ($current_path == $webhook_path) {
    return false;
  }
  
  return $available;
}
add_filter ('wp_is_application_passwords_available', 'bypass_application_passwords_for_webhook');

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants