Skip to content

Commit f1ce24e

Browse files
committed
Ensure all filters/errors start with json_oauth1_
1 parent 284a127 commit f1ce24e

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

authorize-page.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public function register_hooks() {
99
public function render_page() {
1010
// Check required fields
1111
if ( empty( $_REQUEST['oauth_token'] ) ) {
12-
$error = new WP_Error( 'json_oauth_missing_param', sprintf( __( 'Missing parameter %s' ), 'oauth_token' ), array( 'status' => 400 ) );
12+
$error = new WP_Error( 'json_oauth1_missing_param', sprintf( __( 'Missing parameter %s' ), 'oauth_token' ), array( 'status' => 400 ) );
1313
$this->display_error( $error );
1414
exit;
1515
}

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function get_parameters( $require_token = true ) {
100100
),
101101
implode(', ', $errors )
102102
);
103-
return new WP_Error( 'oauth1_missing_parameter', $message, array( 'status' => 401 ) );
103+
return new WP_Error( 'json_oauth1_missing_parameter', $message, array( 'status' => 401 ) );
104104
}
105105

106106
return $params;
@@ -177,7 +177,7 @@ public function dispatch( $route ) {
177177
return $params;
178178
}
179179
if ( empty( $params ) ) {
180-
return new WP_Error( 'oauth1_missing_parameter', __( 'No OAuth parameters supplied' ), array( 'status' => 400 ) );
180+
return new WP_Error( 'json_oauth1_missing_parameter', __( 'No OAuth parameters supplied' ), array( 'status' => 400 ) );
181181
}
182182

183183
return $this->generate_request_token( $params );
@@ -189,7 +189,7 @@ public function dispatch( $route ) {
189189
return $params;
190190
}
191191
if ( empty( $params ) ) {
192-
return new WP_Error( 'oauth1_missing_parameter', __( 'No OAuth parameters supplied' ), array( 'status' => 400 ) );
192+
return new WP_Error( 'json_oauth1_missing_parameter', __( 'No OAuth parameters supplied' ), array( 'status' => 400 ) );
193193
}
194194

195195
return $this->generate_access_token(
@@ -198,7 +198,7 @@ public function dispatch( $route ) {
198198
);
199199

200200
default:
201-
return new WP_Error( 'oauth1_invalid_route', __( 'Route is invalid' ), array( 'status' => 404 ) );
201+
return new WP_Error( 'json_oauth1_invalid_route', __( 'Route is invalid' ), array( 'status' => 404 ) );
202202
}
203203
}
204204

@@ -239,7 +239,7 @@ public function check_token( $token, $consumer_key ) {
239239
}
240240

241241
if ( $token['consumer'] !== $consumer->ID ) {
242-
return new WP_Error( 'oauth1_consumer_mismatch', __( 'Token is not registered for the given consumer' ), array( 'status' => 401 ) );
242+
return new WP_Error( 'json_oauth1_consumer_mismatch', __( 'Token is not registered for the given consumer' ), array( 'status' => 401 ) );
243243
}
244244

245245
return array( $consumer, new WP_User( $token['user'] ) );
@@ -255,13 +255,13 @@ public function get_request_token( $key ) {
255255
$data = get_option( 'oauth1_request_' . $key, null );
256256

257257
if ( empty( $data ) ) {
258-
return new WP_Error( 'json_oauth_invalid_token', __( 'Invalid token' ), array( 'status' => 400 ) );
258+
return new WP_Error( 'json_oauth1_invalid_token', __( 'Invalid token' ), array( 'status' => 400 ) );
259259
}
260260

261261
// Check expiration
262262
if ( $data['expiration'] < time() ) {
263263
$this->remove_request_token( $key );
264-
return new WP_Error( 'oauth1_expired_token', __( 'OAuth request token has expired' ), array( 'status' => 401 ) );
264+
return new WP_Error( 'json_oauth1_expired_token', __( 'OAuth request token has expired' ), array( 'status' => 401 ) );
265265
}
266266

267267
return $data;
@@ -290,15 +290,15 @@ public function generate_request_token( $params ) {
290290
}
291291

292292
// Generate token
293-
$key = apply_filters( 'oauth1_request_token_key', wp_generate_password( self::TOKEN_KEY_LENGTH, false ) );
293+
$key = apply_filters( 'json_oauth1_request_token_key', wp_generate_password( self::TOKEN_KEY_LENGTH, false ) );
294294
$data = array(
295295
'key' => $key,
296296
'secret' => wp_generate_password( self::TOKEN_SECRET_LENGTH, false ),
297297
'consumer' => $consumer->ID,
298298
'authorized' => false,
299299
'expiration' => time() + 24 * HOUR_IN_SECONDS,
300300
);
301-
$data = apply_filters( 'oauth1_request_token_data', $data );
301+
$data = apply_filters( 'json_oauth1_request_token_data', $data );
302302
add_option( 'oauth1_request_' . $key, $data, null, 'no' );
303303

304304
$data = array(
@@ -356,7 +356,7 @@ public function generate_access_token( $oauth_consumer_key, $oauth_token ) {
356356

357357
// Check verification
358358
if ( $token['authorized'] !== true ) {
359-
return new WP_Error( 'oauth1_unauthorized_token', __( 'OAuth token has not been authorized' ), array( 'status' => 401 ) );
359+
return new WP_Error( 'json_oauth1_unauthorized_token', __( 'OAuth token has not been authorized' ), array( 'status' => 401 ) );
360360
}
361361

362362
$consumer = $this->get_consumer( $oauth_consumer_key );
@@ -365,14 +365,14 @@ public function generate_access_token( $oauth_consumer_key, $oauth_token ) {
365365
}
366366

367367
// Issue access token
368-
$key = apply_filters( 'oauth1_access_token_key', wp_generate_password( self::TOKEN_KEY_LENGTH, false ) );
368+
$key = apply_filters( 'json_oauth1_access_token_key', wp_generate_password( self::TOKEN_KEY_LENGTH, false ) );
369369
$data = array(
370370
'key' => $key,
371371
'secret' => wp_generate_password( self::TOKEN_SECRET_LENGTH, false ),
372372
'consumer' => $consumer->ID,
373373
'user' => $token['user'],
374374
);
375-
$data = apply_filters( 'oauth1_access_token_data', $data );
375+
$data = apply_filters( 'json_oauth1_access_token_data', $data );
376376
add_option( 'oauth1_access_' . $key, $data, null, 'no' );
377377

378378
// Delete the request token
@@ -395,11 +395,11 @@ public function generate_access_token( $oauth_consumer_key, $oauth_token ) {
395395
public function revoke_access_token( $key ) {
396396
$data = $this->get_access_token( $key );
397397
if ( empty( $data ) ) {
398-
return new WP_Error( 'oauth1_invalid_token', __( 'Access token does not exist' ), array( 'status' => 401 ) );
398+
return new WP_Error( 'json_oauth1_invalid_token', __( 'Access token does not exist' ), array( 'status' => 401 ) );
399399
}
400400

401401
delete_option( 'oauth1_access_' . $key );
402-
do_action( 'oauth1_revoke_token', $data, $key );
402+
do_action( 'json_oauth1_revoke_token', $data, $key );
403403

404404
return true;
405405
}
@@ -441,7 +441,7 @@ protected function check_oauth_signature( $consumer, $oauth_params, $token = nul
441441

442442
// sort parameters
443443
if ( ! uksort( $params, 'strcmp' ) )
444-
return new WP_Error( 'oauth1_failed_parameter_sort', __( 'Invalid Signature - failed to sort parameters' ), array( 'status' => 401 ) );
444+
return new WP_Error( 'json_oauth1_failed_parameter_sort', __( 'Invalid Signature - failed to sort parameters' ), array( 'status' => 401 ) );
445445

446446
// form query string
447447
$query_params = array();
@@ -468,13 +468,13 @@ protected function check_oauth_signature( $consumer, $oauth_params, $token = nul
468468
break;
469469

470470
default:
471-
return new WP_Error( 'oauth1_invalid_signature_method', __( 'Signature method is invalid' ), array( 'status' => 401 ) );
471+
return new WP_Error( 'json_oauth1_invalid_signature_method', __( 'Signature method is invalid' ), array( 'status' => 401 ) );
472472
}
473473

474474
$signature = base64_encode( hash_hmac( $hash_algorithm, $string_to_sign, $key, true ) );
475475

476476
if ( $signature !== $consumer_signature ) {
477-
return new WP_Error( 'oauth1_signature_mismatch', __( 'OAuth signature does not match' ), array( 'status' => 401 ) );
477+
return new WP_Error( 'json_oauth1_signature_mismatch', __( 'OAuth signature does not match' ), array( 'status' => 401 ) );
478478
}
479479

480480
return true;
@@ -507,18 +507,18 @@ protected function normalize_parameters( &$key, &$value ) {
507507
* @return boolean|WP_Error True on success, error otherwise
508508
*/
509509
protected function check_oauth_timestamp_and_nonce( $consumer, $timestamp, $nonce ) {
510-
$valid_window = apply_filters( 'json_oauth_timestamp_window', 15 * MINUTE_IN_SECONDS );
510+
$valid_window = apply_filters( 'json_oauth1_timestamp_window', 15 * MINUTE_IN_SECONDS );
511511

512512
if ( ( $timestamp < time() - $valid_window ) || ( $timestamp > time() + $valid_window ) )
513-
return new WP_Error( 'oauth1_invalid_timestamp', __( 'Invalid timestamp' ), array( 'status' => 401 ) );
513+
return new WP_Error( 'json_oauth1_invalid_timestamp', __( 'Invalid timestamp' ), array( 'status' => 401 ) );
514514

515515
$used_nonces = $consumer->nonces;
516516

517517
if ( empty( $used_nonces ) )
518518
$used_nonces = array();
519519

520520
if ( in_array( $nonce, $used_nonces ) )
521-
return new WP_Error( 'oauth1_nonce_already_used', __( 'Invalid nonce - nonce has already been used' ), array( 'status' => 401 ) );
521+
return new WP_Error( 'json_oauth1_nonce_already_used', __( 'Invalid nonce - nonce has already been used' ), array( 'status' => 401 ) );
522522

523523
$used_nonces[ $timestamp ] = $nonce;
524524

lib/class-wp-json-authentication.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,4 @@ public function add_consumer( $params ) {
8383

8484
return get_post( $ID );
8585
}
86-
}
86+
}

0 commit comments

Comments
 (0)