Skip to content

Commit c31e6b9

Browse files
committed
new method, retrieve_authorization_headers, for checking for the authorization headers in $_SERVER['HTTP_AUTHORIZATION'] as well as getallheaders if the function exists
1 parent 45197ec commit c31e6b9

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

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

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,32 @@ public function parse_header( $header ) {
6060

6161
}
6262

63+
public function retrieve_authorization_headers() {
64+
$auth_headers = ! empty( $_SERVER['HTTP_AUTHORIZATION'] ) ? $_SERVER['HTTP_AUTHORIZATION'] : false;
65+
66+
if ( ! $auth_headers && function_exists( 'getallheaders' ) ) {
67+
$all_headers = getallheaders();
68+
$auth_headers = isset( $all_headers['Authorization'] ) ? $all_headers['Authorization'] : false;
69+
}
70+
71+
return $auth_headers;
72+
}
73+
6374
public function get_parameters( $require_token = true, $extra = array() ) {
6475
$params = array_merge( $_GET, $_POST );
6576
$params = wp_unslash( $params );
6677

67-
if ( ! empty( $_SERVER['HTTP_AUTHORIZATION'] ) ) {
68-
$header = wp_unslash( $_SERVER['HTTP_AUTHORIZATION'] );
78+
$auth_headers = $this->retrieve_authorization_headers();
79+
80+
if ( ! empty( $auth_headers ) ) {
81+
$auth_headers = wp_unslash( $auth_headers );
6982

7083
// Trim leading spaces
71-
$header = trim( $header );
84+
$auth_headers = trim( $auth_headers );
7285

73-
$header_params = $this->parse_header( $header );
74-
if ( ! empty( $header_params ) ) {
75-
$params = array_merge( $params, $header_params );
86+
$auth_header_params = $this->parse_header( $auth_headers );
87+
if ( ! empty( $auth_header_params ) ) {
88+
$params = array_merge( $params, $auth_header_params );
7689
}
7790
}
7891

@@ -504,6 +517,7 @@ public function revoke_access_token( $key ) {
504517
* @return boolean|WP_Error True on success, error otherwise
505518
*/
506519
protected function check_oauth_signature( $consumer, $oauth_params, $token = null ) {
520+
507521
$http_method = strtoupper( $_SERVER['REQUEST_METHOD'] );
508522

509523
switch ( $http_method ) {

0 commit comments

Comments
 (0)