@@ -54,7 +54,7 @@ public function __construct( $private_api_key ) {
5454 * @param string $path
5555 * @param array $pathArguments
5656 * @param array $queryArguments
57- * @param null|array $payload
57+ * @param null|array $payload
5858 *
5959 * @return void
6060 */
@@ -70,7 +70,7 @@ public function process( $path, array $pathArguments, array $queryArguments, $pa
7070 * @param string $path
7171 * @param array $pathArguments
7272 * @param array $queryArguments
73- * @param null|array $payload
73+ * @param null|array $payload
7474 *
7575 * @return array
7676 */
@@ -95,68 +95,65 @@ public function route( $path, array $pathArguments, array $queryArguments, $payl
9595 }
9696 }
9797
98- /**
99- * @return bool
100- */
101- private function verifyAuthentication ()
102- {
103- $ privateKey = $ this ->private_api_key ;
104-
105- $ authorization = $ this ->getAuthorizationFromRequest ();
106- if (!$ authorization || empty ($ privateKey )) {
107- return false ;
108- }
109-
110- return ($ authorization === $ privateKey );
111- }
112-
113- private function getAuthorizationFromRequest ()
114- {
115- $ token = isset ( $ _GET ['access_token ' ] ) ? stripslashes_deep ( $ _GET ['access_token ' ] ) : false ;
116- if ($ token ) {
117- return $ token ;
118- }
119-
120- if (function_exists ('getallheaders ' )) {
121- $ headers = getallheaders ();
122- } else {
123- $ headers = $ this ->getallheaders ();
124- }
125- $ headers = array_change_key_case ($ headers , CASE_LOWER );
126-
127- if (isset ($ headers ['authorization ' ])) {
128- return trim (str_replace ('Bearer ' , '' , $ headers ['authorization ' ]));
129- }
130-
131- return false ;
132- }
133-
134- private function getallheaders ()
135- {
136- $ headers = array ();
137- $ copy_server = array (
138- 'CONTENT_TYPE ' => 'content-type ' ,
139- 'CONTENT_LENGTH ' => 'content-length ' ,
140- 'CONTENT_MD5 ' => 'content-md5 ' ,
141- );
142-
143- foreach ($ _SERVER as $ name => $ value ) {
144- if (substr ($ name , 0 , 5 ) === 'HTTP_ ' ) {
145- $ name = substr ($ name , 5 );
146- if (!isset ($ copy_server [$ name ]) || !isset ($ _SERVER [$ name ])) {
147- $ headers [str_replace (' ' , '- ' , strtolower (str_replace ('_ ' , ' ' , $ name )))] = $ value ;
148- }
149- } elseif (isset ($ copy_server [$ name ])) {
150- $ headers [$ copy_server [$ name ]] = $ value ;
151- }
152- }
153-
154- if (!isset ($ headers ['authorization ' ])) {
155- if (isset ($ _SERVER ['REDIRECT_HTTP_AUTHORIZATION ' ])) {
156- $ headers ['authorization ' ] = $ _SERVER ['REDIRECT_HTTP_AUTHORIZATION ' ];
157- }
158- }
159-
160- return $ headers ;
161- }
98+ /**
99+ * @return bool
100+ */
101+ private function verifyAuthentication () {
102+ $ privateKey = $ this ->private_api_key ;
103+
104+ $ authorization = $ this ->getAuthorizationFromRequest ();
105+ if ( ! $ authorization || empty ( $ privateKey ) ) {
106+ return false ;
107+ }
108+
109+ return ($ authorization === $ privateKey );
110+ }
111+
112+ private function getAuthorizationFromRequest () {
113+ $ token = isset ( $ _GET ['access_token ' ] ) ? stripslashes_deep ( $ _GET ['access_token ' ] ) : false ;
114+ if ( $ token ) {
115+ return $ token ;
116+ }
117+
118+ if ( function_exists ( 'getallheaders ' ) ) {
119+ $ headers = getallheaders ();
120+ } else {
121+ $ headers = $ this ->getallheaders ();
122+ }
123+ $ headers = array_change_key_case ( $ headers , CASE_LOWER );
124+
125+ if ( isset ( $ headers ['authorization ' ] ) ) {
126+ return trim ( str_replace ( 'Bearer ' , '' , $ headers ['authorization ' ] ) );
127+ }
128+
129+ return false ;
130+ }
131+
132+ private function getallheaders () {
133+ $ headers = array ();
134+ $ copy_server = array (
135+ 'CONTENT_TYPE ' => 'content-type ' ,
136+ 'CONTENT_LENGTH ' => 'content-length ' ,
137+ 'CONTENT_MD5 ' => 'content-md5 ' ,
138+ );
139+
140+ foreach ( $ _SERVER as $ name => $ value ) {
141+ if ( substr ( $ name , 0 , 5 ) === 'HTTP_ ' ) {
142+ $ name = substr ( $ name , 5 );
143+ if ( ! isset ( $ copy_server [ $ name ] ) || ! isset ( $ _SERVER [ $ name ] ) ) {
144+ $ headers [ str_replace ( ' ' , '- ' , strtolower ( str_replace ( '_ ' , ' ' , $ name ) ) ) ] = $ value ;
145+ }
146+ } elseif ( isset ( $ copy_server [ $ name ] ) ) {
147+ $ headers [ $ copy_server [ $ name ] ] = $ value ;
148+ }
149+ }
150+
151+ if ( ! isset ( $ headers ['authorization ' ] ) ) {
152+ if ( isset ( $ _SERVER ['REDIRECT_HTTP_AUTHORIZATION ' ] ) ) {
153+ $ headers ['authorization ' ] = $ _SERVER ['REDIRECT_HTTP_AUTHORIZATION ' ];
154+ }
155+ }
156+
157+ return $ headers ;
158+ }
162159}
0 commit comments