@@ -115,7 +115,7 @@ public function get_parameters( $require_token = true, $extra = array() ) {
115
115
_n (
116
116
'Missing OAuth parameter %s ' ,
117
117
'Missing OAuth parameters %s ' ,
118
- count ( $ errors )
118
+ count ( $ errors )
119
119
),
120
120
implode (', ' , $ errors )
121
121
);
@@ -431,7 +431,7 @@ public function get_access_token( $oauth_token ) {
431
431
/**
432
432
* Generate a new access token
433
433
*
434
- * @param string $oauth_consumer_key Consumer key
434
+ * @param string $oauth_consumer_key Consumer key
435
435
* @param string $oauth_token Request token key
436
436
* @return WP_Error|array OAuth token data on success, error otherwise
437
437
*/
@@ -528,19 +528,13 @@ protected function check_oauth_signature( $consumer, $oauth_params, $token = nul
528
528
unset( $ params ['oauth_signature ' ] );
529
529
530
530
// normalize parameter key/values
531
- array_walk ( $ params , array ( $ this , 'normalize_parameters ' ) );
531
+ array_walk_recursive ( $ params , array ( $ this , 'normalize_parameters ' ) );
532
532
533
533
// sort parameters
534
534
if ( ! uksort ( $ params , 'strcmp ' ) )
535
535
return new WP_Error ( 'json_oauth1_failed_parameter_sort ' , __ ( 'Invalid Signature - failed to sort parameters ' ), array ( 'status ' => 401 ) );
536
536
537
- // form query string
538
- $ query_params = array ();
539
-
540
- foreach ( $ params as $ param_key => $ param_value ) {
541
- $ query_params [] = $ param_key . '%3D ' . $ param_value ; // join with equals sign
542
- }
543
- $ query_string = implode ( '%26 ' , $ query_params ); // join with ampersand
537
+ $ query_string = $ this ->create_signature_string ( $ params );
544
538
545
539
$ token = (array ) $ token ;
546
540
$ string_to_sign = $ http_method . '& ' . $ base_request_uri . '& ' . $ query_string ;
@@ -558,7 +552,7 @@ protected function check_oauth_signature( $consumer, $oauth_params, $token = nul
558
552
case 'HMAC-SHA256 ' :
559
553
$ hash_algorithm = 'sha256 ' ;
560
554
break ;
561
-
555
+
562
556
default :
563
557
return new WP_Error ( 'json_oauth1_invalid_signature_method ' , __ ( 'Signature method is invalid ' ), array ( 'status ' => 401 ) );
564
558
}
@@ -572,6 +566,25 @@ protected function check_oauth_signature( $consumer, $oauth_params, $token = nul
572
566
return true ;
573
567
}
574
568
569
+ public function create_signature_string ( $ params ) {
570
+ return implode ( '%26 ' , $ this ->join_with_equals_sign ( $ params ) ); // join with ampersand
571
+ }
572
+
573
+ public function join_with_equals_sign ( $ params , $ query_params = array (), $ key = '' ) {
574
+ foreach ( $ params as $ param_key => $ param_value ) {
575
+ if ( is_array ( $ param_value ) ) {
576
+ $ query_params = $ this ->join_with_equals_sign ( $ param_value , $ query_params , $ param_key );
577
+ } else {
578
+ if ( $ key ) {
579
+ $ param_key = $ key . '[ ' . $ param_key . '] ' ;
580
+ }
581
+ $ string = $ param_key . '= ' . $ param_value ; // join with equals sign
582
+ $ query_params [] = urlencode ( $ string );
583
+ }
584
+ }
585
+ return $ query_params ;
586
+ }
587
+
575
588
/**
576
589
* Normalize each parameter by assuming each parameter may have already been encoded, so attempt to decode, and then
577
590
* re-encode according to RFC 3986
@@ -588,7 +601,7 @@ protected function normalize_parameters( &$key, &$value ) {
588
601
589
602
/**
590
603
* Verify that the timestamp and nonce provided with the request are valid
591
- *
604
+ *
592
605
* This prevents replay attacks against the request. A timestamp is only
593
606
* valid within 15 minutes of the current time, and a nonce is valid if it
594
607
* has not been used within the last 15 minutes.
0 commit comments