Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Consumer.php
Go to the documentation of this file.
1 <?php
23 #require_once 'Zend/Oauth.php';
24 
26 #require_once 'Zend/Uri.php';
27 
29 #require_once 'Zend/Oauth/Http/RequestToken.php';
30 
32 #require_once 'Zend/Oauth/Http/UserAuthorization.php';
33 
35 #require_once 'Zend/Oauth/Http/AccessToken.php';
36 
38 #require_once 'Zend/Oauth/Token/AuthorizedRequest.php';
39 
41 #require_once 'Zend/Oauth/Config.php';
42 
50 {
51  public $switcheroo = false; // replace later when this works
52 
58  protected $_requestToken = null;
59 
65  protected $_accessToken = null;
66 
70  protected $_config = null;
71 
79  public function __construct($options = null)
80  {
81  $this->_config = new Zend_Oauth_Config;
82  if ($options !== null) {
83  if ($options instanceof Zend_Config) {
84  $options = $options->toArray();
85  }
86  $this->_config->setOptions($options);
87  }
88  }
89 
100  public function getRequestToken(
101  array $customServiceParameters = null,
102  $httpMethod = null,
104  ) {
105  if ($request === null) {
106  $request = new Zend_Oauth_Http_RequestToken($this, $customServiceParameters);
107  } elseif($customServiceParameters !== null) {
108  $request->setParameters($customServiceParameters);
109  }
110  if ($httpMethod !== null) {
111  $request->setMethod($httpMethod);
112  } else {
113  $request->setMethod($this->getRequestMethod());
114  }
115  $this->_requestToken = $request->execute();
116  return $this->_requestToken;
117  }
118 
132  public function getRedirectUrl(
133  array $customServiceParameters = null,
135  Zend_Oauth_Http_UserAuthorization $redirect = null
136  ) {
137  if ($redirect === null) {
138  $redirect = new Zend_Oauth_Http_UserAuthorization($this, $customServiceParameters);
139  } elseif($customServiceParameters !== null) {
140  $redirect->setParameters($customServiceParameters);
141  }
142  if ($token !== null) {
143  $this->_requestToken = $token;
144  }
145  return $redirect->getUrl();
146  }
147 
159  public function redirect(
160  array $customServiceParameters = null,
163  ) {
164  if ($token instanceof Zend_Oauth_Http_UserAuthorization) {
165  $request = $token;
166  $token = null;
167  }
168  $redirectUrl = $this->getRedirectUrl($customServiceParameters, $token, $request);
169  header('Location: ' . $redirectUrl);
170  exit(1);
171  }
172 
184  public function getAccessToken(
185  $queryData,
187  $httpMethod = null,
189  ) {
190  $authorizedToken = new Zend_Oauth_Token_AuthorizedRequest($queryData);
191  if (!$authorizedToken->isValid()) {
192  #require_once 'Zend/Oauth/Exception.php';
193  throw new Zend_Oauth_Exception(
194  'Response from Service Provider is not a valid authorized request token');
195  }
196  if ($request === null) {
198  }
199 
200  // OAuth 1.0a Verifier
201  if ($authorizedToken->getParam('oauth_verifier') !== null) {
202  $params = array_merge($request->getParameters(), array(
203  'oauth_verifier' => $authorizedToken->getParam('oauth_verifier')
204  ));
205  $request->setParameters($params);
206  }
207  if ($httpMethod !== null) {
208  $request->setMethod($httpMethod);
209  } else {
210  $request->setMethod($this->getRequestMethod());
211  }
212  if (isset($token)) {
213  if ($authorizedToken->getToken() !== $token->getToken()) {
214  #require_once 'Zend/Oauth/Exception.php';
215  throw new Zend_Oauth_Exception(
216  'Authorized token from Service Provider does not match'
217  . ' supplied Request Token details'
218  );
219  }
220  } else {
221  #require_once 'Zend/Oauth/Exception.php';
222  throw new Zend_Oauth_Exception('Request token must be passed to method');
223  }
224  $this->_requestToken = $token;
225  $this->_accessToken = $request->execute();
226  return $this->_accessToken;
227  }
228 
235  public function getLastRequestToken()
236  {
237  return $this->_requestToken;
238  }
239 
246  public function getLastAccessToken()
247  {
248  return $this->_accessToken;
249  }
250 
256  public function getToken()
257  {
258  return $this->_accessToken;
259  }
260 
271  public function __call($method, array $args)
272  {
273  if (!method_exists($this->_config, $method)) {
274  #require_once 'Zend/Oauth/Exception.php';
275  throw new Zend_Oauth_Exception('Method does not exist: '.$method);
276  }
277  return call_user_func_array(array($this->_config,$method), $args);
278  }
279 }
getRedirectUrl(array $customServiceParameters=null, Zend_Oauth_Token_Request $token=null, Zend_Oauth_Http_UserAuthorization $redirect=null)
Definition: Consumer.php:132
redirect(array $customServiceParameters=null, Zend_Oauth_Token_Request $token=null, Zend_Oauth_Http_UserAuthorization $request=null)
Definition: Consumer.php:159
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
exit
Definition: redirect.phtml:12
__construct($options=null)
Definition: Consumer.php:79
$method
Definition: info.phtml:13
getAccessToken( $queryData, Zend_Oauth_Token_Request $token, $httpMethod=null, Zend_Oauth_Http_AccessToken $request=null)
Definition: Consumer.php:184
__call($method, array $args)
Definition: Consumer.php:271
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18
getRequestToken(array $customServiceParameters=null, $httpMethod=null, Zend_Oauth_Http_RequestToken $request=null)
Definition: Consumer.php:100