Skip to content

Commit 110cc71

Browse files
committed
Merge pull request WP-API#35 from jtsternberg/master
Check auth headers in multiple locations
2 parents 317cf23 + 8cc8159 commit 110cc71

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

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

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,33 @@ 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( 'apache_request_headers' ) ) {
67+
$all_headers = apache_request_headers();
68+
69+
$auth_headers = array_key_exists( 'Authorization', $all_headers ) ? $all_headers['Authorization'] : false;
70+
}
71+
72+
return $auth_headers;
73+
}
74+
6375
public function get_parameters( $require_token = true, $extra = array() ) {
6476
$params = array_merge( $_GET, $_POST );
6577
$params = wp_unslash( $params );
6678

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

7084
// Trim leading spaces
71-
$header = trim( $header );
85+
$auth_headers = trim( $auth_headers );
7286

73-
$header_params = $this->parse_header( $header );
74-
if ( ! empty( $header_params ) ) {
75-
$params = array_merge( $params, $header_params );
87+
$auth_header_params = $this->parse_header( $auth_headers );
88+
if ( ! empty( $auth_header_params ) ) {
89+
$params = array_merge( $params, $auth_header_params );
7690
}
7791
}
7892

@@ -504,6 +518,7 @@ public function revoke_access_token( $key ) {
504518
* @return boolean|WP_Error True on success, error otherwise
505519
*/
506520
protected function check_oauth_signature( $consumer, $oauth_params, $token = null ) {
521+
507522
$http_method = strtoupper( $_SERVER['REQUEST_METHOD'] );
508523

509524
switch ( $http_method ) {

0 commit comments

Comments
 (0)