Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
All Data Structures Namespaces Files Functions Variables Pages
SignatureAbstract.php
Go to the documentation of this file.
1 <?php
23 #require_once 'Zend/Oauth/Http/Utility.php';
24 
26 #require_once 'Zend/Uri/Http.php';
27 
35 {
40  protected $_hashAlgorithm = null;
41 
46  protected $_key = null;
47 
52  protected $_consumerSecret = null;
53 
58  protected $_tokenSecret = '';
59 
68  public function __construct($consumerSecret, $tokenSecret = null, $hashAlgo = null)
69  {
70  $this->_consumerSecret = $consumerSecret;
71  if (isset($tokenSecret)) {
72  $this->_tokenSecret = $tokenSecret;
73  }
74  $this->_key = $this->_assembleKey();
75  if (isset($hashAlgo)) {
76  $this->_hashAlgorithm = $hashAlgo;
77  }
78  }
79 
88  public abstract function sign(array $params, $method = null, $url = null);
89 
97  {
98  $uri = Zend_Uri_Http::fromString($url);
99  if ($uri->getScheme() == 'http' && $uri->getPort() == '80') {
100  $uri->setPort('');
101  } elseif ($uri->getScheme() == 'https' && $uri->getPort() == '443') {
102  $uri->setPort('');
103  }
104  $uri->setQuery('');
105  $uri->setFragment('');
106  $uri->setHost(strtolower($uri->getHost()));
107  return $uri->getUri(true);
108  }
109 
115  protected function _assembleKey()
116  {
117  $parts = array($this->_consumerSecret);
118  if ($this->_tokenSecret !== null) {
119  $parts[] = $this->_tokenSecret;
120  }
121  foreach ($parts as $key => $secret) {
122  $parts[$key] = Zend_Oauth_Http_Utility::urlEncode($secret);
123  }
124  return implode('&', $parts);
125  }
126 
135  protected function _getBaseSignatureString(array $params, $method = null, $url = null)
136  {
137  $encodedParams = array();
138  foreach ($params as $key => $value) {
139  $encodedParams[Zend_Oauth_Http_Utility::urlEncode($key)] =
141  }
142  $baseStrings = array();
143  if (isset($method)) {
144  $baseStrings[] = strtoupper($method);
145  }
146  if (isset($url)) {
147  // should normalise later
148  $baseStrings[] = Zend_Oauth_Http_Utility::urlEncode(
150  );
151  }
152  if (isset($encodedParams['oauth_signature'])) {
153  unset($encodedParams['oauth_signature']);
154  }
155  $baseStrings[] = Zend_Oauth_Http_Utility::urlEncode(
156  $this->_toByteValueOrderedQueryString($encodedParams)
157  );
158  return implode('&', $baseStrings);
159  }
160 
167  protected function _toByteValueOrderedQueryString(array $params)
168  {
169  $return = array();
170  uksort($params, 'strnatcmp');
171  foreach ($params as $key => $value) {
172  if (is_array($value)) {
173  natsort($value);
174  foreach ($value as $keyduplicate) {
175  $return[] = $key . '=' . $keyduplicate;
176  }
177  } else {
178  $return[] = $key . '=' . $value;
179  }
180  }
181  return implode('&', $return);
182  }
183 }
static urlEncode($value)
Definition: Utility.php:211
sign(array $params, $method=null, $url=null)
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__construct($consumerSecret, $tokenSecret=null, $hashAlgo=null)
_getBaseSignatureString(array $params, $method=null, $url=null)
$value
Definition: gender.phtml:16
$method
Definition: info.phtml:13
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18