Skip to content

Commit 55f641f

Browse files
committed
Merge pull request WP-API#9 from WP-API/avoid-infinite-recursion
Avoid attempting to authenticate on internal requests
2 parents dd672a7 + b88afaf commit 55f641f

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/class-wp-json-authentication-oauth1.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ class WP_JSON_Authentication_OAuth1 extends WP_JSON_Authentication {
2727
*/
2828
protected $auth_status = null;
2929

30+
/**
31+
* Should we attempt to run?
32+
*
33+
* Stops infinite recursion in certain circumstances.
34+
* @var boolean
35+
*/
36+
protected $should_attempt = true;
37+
3038
/**
3139
* Parse the Authorization header into parameters
3240
*
@@ -129,7 +137,7 @@ public function get_parameters( $require_token = true, $extra = array() ) {
129137
* @return WP_User|null|WP_Error Authenticated user on success, null if no OAuth data supplied, error otherwise
130138
*/
131139
public function authenticate( $user ) {
132-
if ( ! empty( $user ) ) {
140+
if ( ! empty( $user ) || ! $this->should_attempt ) {
133141
return $user;
134142
}
135143

lib/class-wp-json-authentication.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public function __construct() {
3131
abstract public function authenticate( $user );
3232

3333
public function get_consumer( $key ) {
34+
$this->should_attempt = false;
35+
3436
$query = new WP_Query();
3537
$consumers = $query->query( array(
3638
'post_type' => 'json_consumer',
@@ -47,6 +49,8 @@ public function get_consumer( $key ) {
4749
),
4850
) );
4951

52+
$this->should_attempt = true;
53+
5054
if ( empty( $consumers ) || empty( $consumers[0] ) )
5155
return new WP_Error( 'json_consumer_notfound', __( 'Consumer Key is invalid' ), array( 'status' => 401 ) );
5256

0 commit comments

Comments
 (0)