From fa516bf27ecb4ab57a6e3cc6a19714cb8daf20ed Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Wed, 2 Mar 2016 13:32:10 -0700 Subject: [PATCH] Run `authenticate` in `get_authentication_errors` Fixes an issue where logged in users could not authenticate requests with their OAuth credentials. * Removes hooking of `authenticate` on `determin_current_user` (which doesn't run or runst too late when the user presents login cookies) * Instead, authenticate directly in `rest_authentication_errors` callback --- lib/class-wp-rest-oauth1.php | 2 ++ oauth-server.php | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/class-wp-rest-oauth1.php b/lib/class-wp-rest-oauth1.php index d95e060..1d5cbdd 100644 --- a/lib/class-wp-rest-oauth1.php +++ b/lib/class-wp-rest-oauth1.php @@ -221,6 +221,8 @@ public function get_authentication_errors( $value ) { return $value; } + $this->authenticate( null ); + return $this->auth_status; } diff --git a/oauth-server.php b/oauth-server.php index 6793853..de5ed48 100644 --- a/oauth-server.php +++ b/oauth-server.php @@ -74,7 +74,6 @@ function rest_oauth1_load() { global $wp_json_authentication_oauth1; $wp_json_authentication_oauth1 = new WP_REST_OAuth1(); - add_filter( 'determine_current_user', array( $wp_json_authentication_oauth1, 'authenticate' ) ); add_filter( 'rest_authentication_errors', array( $wp_json_authentication_oauth1, 'get_authentication_errors' ) ); } add_action( 'init', 'rest_oauth1_load' );