/libs/vendors/Zeflasher/OAuth/Provider/OAuthProvider.php

https://bitbucket.org/csod/x-oauth-php · PHP · 680 lines · 336 code · 86 blank · 258 comment · 32 complexity · 993fd09aa6e4eb6411bdf66134f30f1d MD5 · raw file

  1. <?php
  2. namespace Zeflasher\OAuth\Provider;
  3. /**
  4. * User: zeflasher
  5. * Date: 25/06/12
  6. * Time: 7:47 PM
  7. */
  8. class OAuthProvider
  9. {
  10. /**
  11. * The signature methods handle by this provider
  12. * @protected
  13. * @var array
  14. */
  15. protected $_signature_methods = array();
  16. /**
  17. * If set to true bypass token check
  18. * @protected
  19. * @var bool
  20. */
  21. protected $_is_request_token = false;
  22. /**
  23. * OAuth version used by this provider
  24. * @protected
  25. * @var string
  26. */
  27. protected $_version = '1.0';
  28. /**
  29. * Holds the required parameters needed to process the request
  30. * @protected
  31. * @var array
  32. */
  33. protected $_required_parameters = array ();
  34. /**
  35. * The callback method used to check the consumer
  36. * @private
  37. * @var callback
  38. */
  39. private $__consumer_callback;
  40. /**
  41. * The callback method used to check the token
  42. * @private
  43. * @var callback
  44. */
  45. private $__token_callback;
  46. /**
  47. * The callback method used to check the timestamp
  48. * @private
  49. * @var callback
  50. */
  51. private $__timestamp_callback;
  52. /**
  53. * The callback method used to check the nonce
  54. * @private
  55. * @var callback
  56. */
  57. private $__nonce_callback;
  58. /**
  59. * Are we using xAuth flow
  60. * @var bool
  61. */
  62. private $__is_xauth = false;
  63. /**
  64. * the consumer key
  65. * @var string
  66. */
  67. public $consumer_key;
  68. /**
  69. * the consumer secret
  70. * @var string
  71. */
  72. public $consumer_secret;
  73. /**
  74. * the token key
  75. * @var string
  76. */
  77. public $token_key;
  78. /**
  79. * the token secret
  80. * @var string
  81. */
  82. public $token_secret;
  83. /**
  84. * the callback url once authentication done
  85. * @var string
  86. */
  87. public $callback_url;
  88. /**
  89. * The request object build from the headers/params
  90. * @var \Zeflasher\OAuth\Provider\OAuthRequest;
  91. */
  92. public $request;
  93. /**
  94. * Generates a random string
  95. * @static
  96. * @param int $length The desired token length, in terms of bytes.
  97. * @param bool $strong Setting to TRUE means /dev/random will be used for entropy,
  98. * as otherwise the non-blocking /dev/urandom is used. This parameter is ignored on Windows.
  99. * @return string
  100. */
  101. public static function generate_token($length, $strong)
  102. {
  103. if( @is_readable('/dev/urandom') )
  104. {
  105. $f=fopen( '/dev/urandom', 'r' );
  106. $urandom=fread( $f, $length );
  107. fclose( $f );
  108. }
  109. $return='';
  110. for( $i=0;$i<$length;++$i )
  111. {
  112. if( !isset($urandom) )
  113. {
  114. if( $i%2==0 )
  115. {
  116. mt_srand(time()%2147 * 1000000 + (double)microtime() * 1000000);
  117. }
  118. $rand=48+mt_rand()%64;
  119. }
  120. else
  121. {
  122. $rand=48+ord($urandom[$i])%64;
  123. }
  124. if ($rand>57) $rand+=7;
  125. if ($rand>90) $rand+=6;
  126. if ($rand==123) $rand=45;
  127. if ($rand==124) $rand=46;
  128. $return.=chr($rand);
  129. }
  130. return $return;
  131. }
  132. /**
  133. * Create the provider and sets the following parameters has mandatory
  134. * * oauth_consumer_key
  135. * * oauth_token
  136. * * oauth_signature_method
  137. * * oauth_signature
  138. * * oauth_timestamp
  139. * * oauth_nonce
  140. * * oauth_verifier
  141. */
  142. public function __construct()
  143. {
  144. // construct the query
  145. $this->request = \Zeflasher\OAuth\Provider\OAuthRequest::build();
  146. // by default we are using oauth
  147. $this->set_to_oauth_flow();
  148. }
  149. /**
  150. * Add a parameter to the list of required parameters.
  151. * An error will be thrown if the OAuthRequest does not have all of those.
  152. * By default the required parameters are:
  153. * - \Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_CONSUMER_KEY
  154. * - \Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_TOKEN
  155. * - \Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_SIGNATURE_METHOD
  156. * - \Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_SIGNATURE
  157. * - \Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_TIMESTAMP
  158. * - \Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_NONCE
  159. * - \Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_VERIFIER
  160. * needed for a normal call passing an access token
  161. * @param string $parameter_name
  162. */
  163. public function add_required_parameter($parameter_name)
  164. {
  165. $this->_required_parameters[$parameter_name] = 1;
  166. }
  167. /**
  168. * Remove parameters from the required parameters list.
  169. * Use with caution.
  170. * @param string $parameter_name
  171. */
  172. public function remove_required_parameter($parameter_name)
  173. {
  174. unset($this->_required_parameters[$parameter_name]);
  175. }
  176. /**
  177. * Set the parameter as required.
  178. * If required parameters are not part of the \Zeflasher\OAuth\OAuthRequest object
  179. * the OAUth check will fail and will throw an error
  180. * @param string $parameter_name
  181. * @return bool
  182. */
  183. public function is_required_parameter($parameter_name)
  184. {
  185. if (isset( $this->_required_parameters[$parameter_name]) )
  186. {
  187. return $this->_required_parameters[$parameter_name] == 1;
  188. }
  189. return false;
  190. }
  191. /**
  192. * Add a signature method to this provider
  193. * @param \Zeflasher\OAuth\SignatureMethods\OAuthSignatureMethod $signature_method
  194. */
  195. public function add_signature_method($signature_method)
  196. {
  197. $this->_signature_methods[$signature_method->get_name()] = $signature_method;
  198. }
  199. /**
  200. * Remove a signature method from this provider
  201. * @param \Zeflasher\OAuth\SignatureMethods\OAuthSignatureMethod $signature_method
  202. */
  203. public function remove_signature_method($signature_method)
  204. {
  205. unset( $this->_signature_methods[$signature_method->get_name()] );
  206. }
  207. /**
  208. * Set the is_request_token flag
  209. * This will bypass the token check (token_handler won't be call)
  210. * @param $bypass_token_check
  211. */
  212. public function is_request_token( $bypass_token_check )
  213. {
  214. $this->_is_request_token = $bypass_token_check;
  215. }
  216. /**
  217. * Call this function before the check_oauth_request when you want to grant a request token
  218. * Basically it disabled the token_handler check and force the oauth_callback parameter
  219. * This unset the following required parameters:
  220. * * \Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_TOKEN
  221. * * \Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_VERIFIER
  222. * and set the following ones
  223. * * \Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_CALLBACK
  224. * It also sets is_request_token to true, i.e token_handler won't be called
  225. */
  226. public function set_request_token_query()
  227. {
  228. $this->is_request_token(true);
  229. $this->remove_required_parameter(\Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_TOKEN);
  230. $this->remove_required_parameter(\Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_VERIFIER);
  231. $this->add_required_parameter(\Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_CALLBACK);
  232. }
  233. /**
  234. * Set the provider to accept OAuth query for access token
  235. * This unset the following required parameters:
  236. * * \Zeflasher\OAuth\OAuthConstants::X_AUTH_USERNAME
  237. * * \Zeflasher\OAuth\OAuthConstants::X_AUTH_PASSWORD
  238. * * \Zeflasher\OAuth\OAuthConstants::X_AUTH_MODE
  239. * and set the following ones
  240. * * \Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_CONSUMER_KEY
  241. * * \Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_TOKEN
  242. * * \Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_SIGNATURE_METHOD
  243. * * \Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_SIGNATURE
  244. * * \Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_TIMESTAMP
  245. * * \Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_NONCE
  246. * * \Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_VERIFIER
  247. */
  248. public function set_to_oauth_flow()
  249. {
  250. $this->remove_required_parameter(\Zeflasher\OAuth\OAuthConstants::X_AUTH_USERNAME);
  251. $this->remove_required_parameter(\Zeflasher\OAuth\OAuthConstants::X_AUTH_PASSWORD);
  252. $this->remove_required_parameter(\Zeflasher\OAuth\OAuthConstants::X_AUTH_MODE);
  253. $this->add_required_parameter(\Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_CONSUMER_KEY);
  254. $this->add_required_parameter(\Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_TOKEN);
  255. $this->add_required_parameter(\Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_SIGNATURE_METHOD);
  256. $this->add_required_parameter(\Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_SIGNATURE);
  257. $this->add_required_parameter(\Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_TIMESTAMP);
  258. $this->add_required_parameter(\Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_NONCE);
  259. $this->__is_xauth = false;
  260. }
  261. /**
  262. * Set the provider to accept xAuth query for access token
  263. * This unset the following required parameters:
  264. * * \Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_TOKEN
  265. * * \Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_VERIFIER
  266. * * \Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_CALLBACK
  267. * and set the following ones
  268. * * \Zeflasher\OAuth\OAuthConstants::X_AUTH_USERNAME
  269. * * \Zeflasher\OAuth\OAuthConstants::X_AUTH_PASSWORD
  270. * * \Zeflasher\OAuth\OAuthConstants::X_AUTH_MODE
  271. * *
  272. * * \Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_CONSUMER_KEY
  273. * * \Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_SIGNATURE_METHOD
  274. * * \Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_SIGNATURE
  275. * * \Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_TIMESTAMP
  276. * * \Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_NONCE
  277. */
  278. public function set_to_xauth_flow()
  279. {
  280. $this->is_request_token(true);
  281. $this->remove_required_parameter(\Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_TOKEN);
  282. $this->remove_required_parameter(\Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_VERIFIER);
  283. $this->remove_required_parameter(\Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_CALLBACK);
  284. $this->add_required_parameter(\Zeflasher\OAuth\OAuthConstants::X_AUTH_USERNAME);
  285. $this->add_required_parameter(\Zeflasher\OAuth\OAuthConstants::X_AUTH_PASSWORD);
  286. $this->add_required_parameter(\Zeflasher\OAuth\OAuthConstants::X_AUTH_MODE);
  287. $this->add_required_parameter(\Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_CONSUMER_KEY);
  288. $this->add_required_parameter(\Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_SIGNATURE_METHOD);
  289. $this->add_required_parameter(\Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_SIGNATURE);
  290. $this->add_required_parameter(\Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_TIMESTAMP);
  291. $this->add_required_parameter(\Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_NONCE);
  292. $this->__is_xauth = true;
  293. }
  294. /**
  295. * Call the consumer_handler callback
  296. * and throw an exception if result of the callback is not \Zeflasher\OAuth\OAuthConstants::OAUTH_OK
  297. * Your callback method __HAS TO__ set $provider->consumer_secret to the right value or the signature will fail
  298. * @throws \Zeflasher\OAuth\OAuthException
  299. */
  300. public function call_consumer_handler()
  301. {
  302. if( is_callable( $this->__consumer_callback ) )
  303. {
  304. $code = call_user_func( $this->__consumer_callback, $this );
  305. if( $code !== \Zeflasher\OAuth\OAuthConstants::OAUTH_OK )
  306. {
  307. throw new \Zeflasher\OAuth\OAuthException('', $code);
  308. }
  309. }
  310. else
  311. {
  312. throw new \Zeflasher\OAuth\OAuthException('The consumer callback is not properly set');
  313. }
  314. }
  315. /**
  316. * Call the token_handler callback
  317. * and throw an exception if result of the callback is not \Zeflasher\OAuth\OAuthConstants::OAUTH_OK
  318. * @throws \Zeflasher\OAuth\OAuthException
  319. */
  320. public function call_token_handler()
  321. {
  322. if( is_callable( $this->__token_callback ) )
  323. {
  324. $code = call_user_func( $this->__token_callback, $this );
  325. if( $code !== \Zeflasher\OAuth\OAuthConstants::OAUTH_OK )
  326. {
  327. throw new \Zeflasher\OAuth\OAuthException('', $code);
  328. }
  329. }
  330. else
  331. {
  332. throw new \Zeflasher\OAuth\OAuthException('The toekn callback is not properly set');
  333. }
  334. }
  335. /**
  336. * Call the token_handler callback
  337. * and throw an exception if result of the callback is not \Zeflasher\OAuth\OAuthConstants::OAUTH_OK
  338. * @throws \Zeflasher\OAuth\OAuthException
  339. */
  340. public function call_timestamp_handler()
  341. {
  342. if( is_callable( $this->__timestamp_callback ) )
  343. {
  344. $code = call_user_func( $this->__timestamp_callback, $this );
  345. if( $code !== \Zeflasher\OAuth\OAuthConstants::OAUTH_OK )
  346. {
  347. throw new \Zeflasher\OAuth\OAuthException('', $code);
  348. }
  349. }
  350. else
  351. {
  352. throw new \Zeflasher\OAuth\OAuthException('The timestamp callback is not properly set');
  353. }
  354. }
  355. /**
  356. * Call the token_handler callback
  357. * and throw an exception if result of the callback is not \Zeflasher\OAuth\OAuthConstants::OAUTH_OK
  358. * @throws \Zeflasher\OAuth\OAuthException
  359. */
  360. public function call_nonce_handler()
  361. {
  362. if( is_callable( $this->__nonce_callback ) )
  363. {
  364. $code = call_user_func( $this->__nonce_callback, $this );
  365. if( $code !== \Zeflasher\OAuth\OAuthConstants::OAUTH_OK )
  366. {
  367. throw new \Zeflasher\OAuth\OAuthException('', $code);
  368. }
  369. }
  370. else
  371. {
  372. throw new \Zeflasher\OAuth\OAuthException('The nonce callback is not properly set', 0);
  373. }
  374. }
  375. /**
  376. * Set the consumer callback
  377. * @param callback $callback_function
  378. */
  379. public function consumer_handler( $callback_function )
  380. {
  381. $this->__consumer_callback = $callback_function;
  382. }
  383. /**
  384. * Set the token callback
  385. * @param callback $callback_function
  386. */
  387. public function token_handler( $callback_function )
  388. {
  389. $this->__token_callback = $callback_function;
  390. }
  391. /**
  392. * Set the timestamp callback
  393. * @param callback $callback_function
  394. */
  395. public function timestamp_handler( $callback_function )
  396. {
  397. $this->__timestamp_callback = $callback_function;
  398. }
  399. /**
  400. * Set the nonce callback
  401. * @param callback $callback_function
  402. */
  403. public function nonce_handler( $callback_function )
  404. {
  405. $this->__nonce_callback = $callback_function;
  406. }
  407. /**
  408. * Check if the request is valid
  409. * This check for:
  410. * - valid consumer (key/secret)
  411. * - valid token (key/secret) if bypassTokenCheck is not set to true
  412. * - valid timestamp threshold
  413. * - valid nonce
  414. * @throws \Zeflasher\OAuth\OAuthException
  415. */
  416. public function check_oauth_request()
  417. {
  418. try
  419. {
  420. // check if we have all the required parameters for the request
  421. $this->__check_requested_parameters();
  422. // check the version if we have made it mandatory
  423. if ( $this->is_required_parameter(\Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_VERSION) )
  424. {
  425. $this->__checkVersion();
  426. }
  427. // check for a valid consumer
  428. $this->call_consumer_handler();
  429. // bypass the request token check if asked for
  430. if( !$this->_is_request_token )
  431. {
  432. // check for a valid token
  433. $this->call_token_handler();
  434. }
  435. // check for valid timestamp
  436. $this->call_timestamp_handler();
  437. // check for valid nonce
  438. $this->call_nonce_handler();
  439. // finally check the signature
  440. $this->__checkSignature();
  441. }
  442. catch (\Zeflasher\OAuth\OAuthException $e)
  443. {
  444. // create a new exception with message and code
  445. $code = $e->getCode();
  446. switch( $code )
  447. {
  448. case \Zeflasher\OAuth\OAuthConstants::OAUTH_SIGNATURE_METHOD_REJECTED:
  449. $message = $e->getMessage();
  450. break;
  451. case \Zeflasher\OAuth\OAuthConstants::OAUTH_PARAMETER_ABSENT:
  452. $message = $e->getMessage();
  453. break;
  454. case \Zeflasher\OAuth\OAuthConstants::OAUTH_CONSUMER_KEY_UNKNOWN:
  455. $message = 'Consumer key unknown';
  456. break;
  457. case \Zeflasher\OAuth\OAuthConstants::OAUTH_CONSUMER_KEY_REFUSED:
  458. $message = 'Consumer key refused';
  459. break;
  460. case \Zeflasher\OAuth\OAuthConstants::OAUTH_BAD_NONCE:
  461. $message = 'Bad nonce';
  462. break;
  463. case \Zeflasher\OAuth\OAuthConstants::OAUTH_BAD_TIMESTAMP:
  464. $message = "Bad time stamp";
  465. break;
  466. case \Zeflasher\OAuth\OAuthConstants::OAUTH_VERIFIER_INVALID:
  467. $message = "Verifier invalid";
  468. break;
  469. case \Zeflasher\OAuth\OAuthConstants::OAUTH_INVALID_SIGNATURE:
  470. $message = $e->getMessage();
  471. break;
  472. case \Zeflasher\OAuth\OAuthConstants::OAUTH_TOKEN_USED:
  473. $message = "OAuth token used";
  474. break;
  475. case \Zeflasher\OAuth\OAuthConstants::OAUTH_TOKEN_EXPIRED:
  476. $message = "OAuth token expired";
  477. break;
  478. case \Zeflasher\OAuth\OAuthConstants::OAUTH_TOKEN_REJECTED:
  479. $message = "OAuth token rejected";
  480. break;
  481. default:
  482. $message = $e->getMessage();
  483. break;
  484. }
  485. throw new \Zeflasher\OAuth\OAuthException($message, $code, $e);
  486. }
  487. }
  488. /**
  489. * Check that all the required parameters are set in the OAuthRequest
  490. * @throws \Zeflasher\OAuth\OAuthException
  491. */
  492. private function __check_requested_parameters()
  493. {
  494. $absentParameters = array();
  495. foreach( $this->_required_parameters as $parameter => $required )
  496. {
  497. if( $required)
  498. {
  499. $requestParam = $this->request->get_parameter($parameter);
  500. // if not set add to the list of absent parameters
  501. if (! isset( $requestParam ) )
  502. {
  503. array_push($absentParameters, $parameter);
  504. }
  505. }
  506. }
  507. if( count($absentParameters) > 0 )
  508. {
  509. throw new \Zeflasher\OAuth\OAuthException("OAuth parameters absent: ".join(', ',$absentParameters), \Zeflasher\OAuth\OAuthConstants::OAUTH_PARAMETER_ABSENT);
  510. }
  511. // now sets the provider variables
  512. $this->consumer_key = $this->request->get_parameter(\Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_CONSUMER_KEY);
  513. // if we are not using xauth and we are not requesting a request token then the OAUTH_TOKEN should be set
  514. if( !$this->__is_xauth && !$this->_is_request_token)
  515. {
  516. $this->token_key = $this->request->get_parameter(\Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_TOKEN);
  517. }
  518. // OAuth mode, requesting request token, get the url callback
  519. else if( $this->_is_request_token )
  520. {
  521. $this->callback_url = $this->request->get_parameter(\Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_CALLBACK);
  522. }
  523. }
  524. /**
  525. * Check the version of the provider against the version pass in the request
  526. * @return string
  527. * @throws \Zeflasher\OAuth\OAuthException
  528. */
  529. private function __checkVersion()
  530. {
  531. $version = $this->request->get_parameter(\Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_VERSION);
  532. if (!$version)
  533. {
  534. // Service Providers MUST assume the protocol version to be 1.0 if this parameter is not present.
  535. // Chapter 7.0 ("Accessing Protected Resources")
  536. $version = '1.0';
  537. }
  538. if ($version !== $this->_version)
  539. {
  540. throw new \Zeflasher\OAuth\OAuthException("OAuth version '$version' not supported");
  541. }
  542. return $version;
  543. }
  544. /**
  545. * Check the signature against the specified method
  546. * The check for required parameters has already be done, no need to repeat it here
  547. * @throws \Zeflasher\OAuth\OAuthException
  548. */
  549. private function __checkSignature()
  550. {
  551. $signature = $this->request->get_parameter(\Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_SIGNATURE);
  552. $signature_method = $this->__get_signature_method($this->request);
  553. $valid_sig = $signature_method->check_signature
  554. (
  555. $this->request,
  556. $this->consumer_secret,
  557. $this->token_secret,
  558. $signature
  559. );
  560. if (!$valid_sig)
  561. {
  562. throw new \Zeflasher\OAuth\OAuthException('Invalid signature', \Zeflasher\OAuth\OAuthConstants::OAUTH_INVALID_SIGNATURE);
  563. }
  564. }
  565. /**
  566. * Call the appropriate signature method
  567. * The check for required parameters has already be done, no need to repeat it here
  568. * @param \Zeflasher\OAuth\Provider\OAuthRequest $request
  569. * @return \Zeflasher\OAuth\SignatureMethods\OAuthSignatureMethod
  570. * @throws \Zeflasher\OAuth\OAuthException
  571. */
  572. private function __get_signature_method($request)
  573. {
  574. $signature_method = $request instanceof \Zeflasher\OAuth\Provider\OAuthRequest
  575. ? $request->get_parameter(\Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_SIGNATURE_METHOD)
  576. : NULL;
  577. if (!$signature_method)
  578. {
  579. // According to chapter 7 ("Accessing Protected Resources") the signature-method
  580. // parameter is required, and we can't just fallback to PLAINTEXT
  581. throw new \Zeflasher\OAuth\OAuthException('No signature method parameter. This parameter is required');
  582. }
  583. if (!in_array($signature_method,
  584. array_keys($this->_signature_methods)))
  585. {
  586. throw new \Zeflasher\OAuth\OAuthException(
  587. "Signature method '$signature_method' not supported " .
  588. "try one of the following: " .
  589. implode(", ", array_keys($this->_signature_methods)), \Zeflasher\OAuth\OAuthConstants::OAUTH_SIGNATURE_METHOD_REJECTED
  590. );
  591. }
  592. return $this->_signature_methods[$signature_method];
  593. }
  594. }