2
0
Просмотр исходного кода

Added support for concatenating all parameter forms from query strings AND post body for signing. Edge usage but required for some services. Fixes ZF-9510

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@22050 44c647ce-9c0f-0410-b52a-842ac1e357ba
padraic 15 лет назад
Родитель
Сommit
e5ddada6af
1 измененных файлов с 37 добавлено и 16 удалено
  1. 37 16
      library/Zend/Oauth/Client.php

+ 37 - 16
library/Zend/Oauth/Client.php

@@ -240,21 +240,10 @@ class Zend_Oauth_Client extends Zend_Http_Client
         $requestMethod = $this->getRequestMethod();
         $query = null;
         if ($requestScheme == Zend_Oauth::REQUEST_SCHEME_HEADER) {
-            $params = array();
-            if (!empty($this->paramsGet)) {
-                $params = array_merge($params, $this->paramsGet);
-                $query  = $this->getToken()->toQueryString(
-                    $this->getUri(true), $this->_config, $params
-                );
-            }
-            if (!empty($this->paramsPost)) {
-                $params = array_merge($params, $this->paramsPost);
-                $query  = $this->getToken()->toQueryString(
-                    $this->getUri(true), $this->_config, $params
-                );
-            }
             $oauthHeaderValue = $this->getToken()->toHeader(
-                $this->getUri(true), $this->_config, $params
+                $this->getUri(true),
+                $this->_config,
+                $this->_getSignableParametersAsQueryString()
             );
             $this->setHeaders('Authorization', $oauthHeaderValue);
         } elseif ($requestScheme == Zend_Oauth::REQUEST_SCHEME_POSTBODY) {
@@ -267,7 +256,9 @@ class Zend_Oauth_Client extends Zend_Http_Client
                 );
             }
             $raw = $this->getToken()->toQueryString(
-                $this->getUri(true), $this->_config, $this->paramsPost
+                $this->getUri(true),
+                $this->_config,
+                $this->_getSignableParametersAsQueryString()
             );
             $this->setRawData($raw);
             $this->paramsPost = array();
@@ -282,7 +273,12 @@ class Zend_Oauth_Client extends Zend_Http_Client
                         (array_key_exists(1, $kvTuple) ? $kvTuple[1] : NULL);
                 }
             }
-
+            if (!empty($this->paramsPost)) {
+                $params = array_merge($params, $this->paramsPost);
+                $query  = $this->getToken()->toQueryString(
+                    $this->getUri(true), $this->_config, $params
+                );
+            }
             $query = $this->getToken()->toQueryString(
                 $this->getUri(true), $this->_config, $params
             );
@@ -295,6 +291,31 @@ class Zend_Oauth_Client extends Zend_Http_Client
     }
 
     /**
+     * Collect all signable parameters into a single array across query string
+     * and POST body. These are returned as a properly formatted single
+     * query string.
+     *
+     * @return string
+     */
+    protected function _getSignableParametersAsQueryString()
+    {
+        $params = array();
+            if (!empty($this->paramsGet)) {
+                $params = array_merge($params, $this->paramsGet);
+                $query  = $this->getToken()->toQueryString(
+                    $this->getUri(true), $this->_config, $params
+                );
+            }
+            if (!empty($this->paramsPost)) {
+                $params = array_merge($params, $this->paramsPost);
+                $query  = $this->getToken()->toQueryString(
+                    $this->getUri(true), $this->_config, $params
+                );
+            }
+            return $params;
+    }
+
+    /**
      * Simple Proxy to the current Zend_Oauth_Config method. It's that instance
      * which holds all configuration methods and values this object also presents
      * as it's API.