@@ -100,7 +100,7 @@ public function get_parameters( $require_token = true ) {
100
100
),
101
101
implode (', ' , $ errors )
102
102
);
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 ) );
104
104
}
105
105
106
106
return $ params ;
@@ -177,7 +177,7 @@ public function dispatch( $route ) {
177
177
return $ params ;
178
178
}
179
179
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 ) );
181
181
}
182
182
183
183
return $ this ->generate_request_token ( $ params );
@@ -189,7 +189,7 @@ public function dispatch( $route ) {
189
189
return $ params ;
190
190
}
191
191
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 ) );
193
193
}
194
194
195
195
return $ this ->generate_access_token (
@@ -198,7 +198,7 @@ public function dispatch( $route ) {
198
198
);
199
199
200
200
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 ) );
202
202
}
203
203
}
204
204
@@ -239,7 +239,7 @@ public function check_token( $token, $consumer_key ) {
239
239
}
240
240
241
241
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 ) );
243
243
}
244
244
245
245
return array ( $ consumer , new WP_User ( $ token ['user ' ] ) );
@@ -255,13 +255,13 @@ public function get_request_token( $key ) {
255
255
$ data = get_option ( 'oauth1_request_ ' . $ key , null );
256
256
257
257
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 ) );
259
259
}
260
260
261
261
// Check expiration
262
262
if ( $ data ['expiration ' ] < time () ) {
263
263
$ 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 ) );
265
265
}
266
266
267
267
return $ data ;
@@ -290,15 +290,15 @@ public function generate_request_token( $params ) {
290
290
}
291
291
292
292
// 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 ) );
294
294
$ data = array (
295
295
'key ' => $ key ,
296
296
'secret ' => wp_generate_password ( self ::TOKEN_SECRET_LENGTH , false ),
297
297
'consumer ' => $ consumer ->ID ,
298
298
'authorized ' => false ,
299
299
'expiration ' => time () + 24 * HOUR_IN_SECONDS ,
300
300
);
301
- $ data = apply_filters ( 'oauth1_request_token_data ' , $ data );
301
+ $ data = apply_filters ( 'json_oauth1_request_token_data ' , $ data );
302
302
add_option ( 'oauth1_request_ ' . $ key , $ data , null , 'no ' );
303
303
304
304
$ data = array (
@@ -356,7 +356,7 @@ public function generate_access_token( $oauth_consumer_key, $oauth_token ) {
356
356
357
357
// Check verification
358
358
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 ) );
360
360
}
361
361
362
362
$ consumer = $ this ->get_consumer ( $ oauth_consumer_key );
@@ -365,14 +365,14 @@ public function generate_access_token( $oauth_consumer_key, $oauth_token ) {
365
365
}
366
366
367
367
// 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 ) );
369
369
$ data = array (
370
370
'key ' => $ key ,
371
371
'secret ' => wp_generate_password ( self ::TOKEN_SECRET_LENGTH , false ),
372
372
'consumer ' => $ consumer ->ID ,
373
373
'user ' => $ token ['user ' ],
374
374
);
375
- $ data = apply_filters ( 'oauth1_access_token_data ' , $ data );
375
+ $ data = apply_filters ( 'json_oauth1_access_token_data ' , $ data );
376
376
add_option ( 'oauth1_access_ ' . $ key , $ data , null , 'no ' );
377
377
378
378
// Delete the request token
@@ -395,11 +395,11 @@ public function generate_access_token( $oauth_consumer_key, $oauth_token ) {
395
395
public function revoke_access_token ( $ key ) {
396
396
$ data = $ this ->get_access_token ( $ key );
397
397
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 ) );
399
399
}
400
400
401
401
delete_option ( 'oauth1_access_ ' . $ key );
402
- do_action ( 'oauth1_revoke_token ' , $ data , $ key );
402
+ do_action ( 'json_oauth1_revoke_token ' , $ data , $ key );
403
403
404
404
return true ;
405
405
}
@@ -441,7 +441,7 @@ protected function check_oauth_signature( $consumer, $oauth_params, $token = nul
441
441
442
442
// sort parameters
443
443
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 ) );
445
445
446
446
// form query string
447
447
$ query_params = array ();
@@ -468,13 +468,13 @@ protected function check_oauth_signature( $consumer, $oauth_params, $token = nul
468
468
break ;
469
469
470
470
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 ) );
472
472
}
473
473
474
474
$ signature = base64_encode ( hash_hmac ( $ hash_algorithm , $ string_to_sign , $ key , true ) );
475
475
476
476
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 ) );
478
478
}
479
479
480
480
return true ;
@@ -507,18 +507,18 @@ protected function normalize_parameters( &$key, &$value ) {
507
507
* @return boolean|WP_Error True on success, error otherwise
508
508
*/
509
509
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 );
511
511
512
512
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 ) );
514
514
515
515
$ used_nonces = $ consumer ->nonces ;
516
516
517
517
if ( empty ( $ used_nonces ) )
518
518
$ used_nonces = array ();
519
519
520
520
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 ) );
522
522
523
523
$ used_nonces [ $ timestamp ] = $ nonce ;
524
524
0 commit comments