TokenProviderInterface.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Oauth;
  7. /**
  8. * TokenProviderInterface provides token manipulation, such as creating a request token and getting an access token
  9. * as well as methods for performing certain validations on tokens and token requests. Consumer methods are also
  10. * provided to help clients manipulating tokens validate and acquire the associated token consumer.
  11. *
  12. * @api
  13. * @since 100.0.2
  14. */
  15. interface TokenProviderInterface
  16. {
  17. /**
  18. * Validate the consumer.
  19. *
  20. * @param ConsumerInterface $consumer The consumer.
  21. * @return bool True if the consumer is valid.
  22. * @throws \Magento\Framework\Oauth\Exception Validation errors.
  23. */
  24. public function validateConsumer($consumer);
  25. /**
  26. * Create a request token for the specified consumer.
  27. * Example:
  28. * <pre>
  29. * array(
  30. * 'oauth_token' => 'gshsjkndtyhwjhdbutfgbsnhtrequikf,
  31. * 'oauth_token_secret' => 'gshsjkndtyhwjhdbutfgbsnhtrequikf'
  32. * )
  33. * </pre>
  34. *
  35. * @param ConsumerInterface $consumer
  36. * @return array The request token and secret.
  37. * @throws \Magento\Framework\Oauth\Exception Validation errors.
  38. */
  39. public function createRequestToken($consumer);
  40. /**
  41. * Validates the request token and verifier. Verifies the request token is associated with the consumer.
  42. *
  43. * @param string $requestToken The 'oauth_token' request token value.
  44. * @param ConsumerInterface $consumer The consumer given the 'oauth_consumer_key'.
  45. * @param string $oauthVerifier The 'oauth_verifier' value.
  46. * @return string The request token secret (i.e. 'oauth_token_secret').
  47. * @throws \Magento\Framework\Oauth\Exception Validation errors.
  48. */
  49. public function validateRequestToken($requestToken, $consumer, $oauthVerifier);
  50. /**
  51. * Retrieve access token for the specified consumer given the consumer key.
  52. * Example:
  53. * <pre>
  54. * array(
  55. * 'oauth_token' => 'gshsjkndtyhwjhdbutfgbsnhtrequikf,
  56. * 'oauth_token_secret' => 'gshsjkndtyhwjhdbutfgbsnhtrequikf'
  57. * )
  58. * </pre>
  59. *
  60. * @param ConsumerInterface $consumer The consumer given the 'oauth_consumer_key'.
  61. * @return array The access token and secret.
  62. * @throws \Magento\Framework\Oauth\Exception Validation errors.
  63. */
  64. public function getAccessToken($consumer);
  65. /**
  66. * Validates the Oauth token type and verifies that it's associated with the consumer.
  67. *
  68. * @param string $accessToken The 'oauth_token' access token value.
  69. * @param ConsumerInterface $consumer The consumer given the 'oauth_consumer_key'.
  70. * @return string The access token secret.
  71. * @throws \Magento\Framework\Oauth\Exception Validation errors.
  72. */
  73. public function validateAccessTokenRequest($accessToken, $consumer);
  74. /**
  75. * Validate an access token string.
  76. *
  77. * @param string $accessToken The 'oauth_token' access token string.
  78. * @return int Consumer ID if the access token is valid.
  79. * @throws \Magento\Framework\Oauth\Exception Validation errors.
  80. */
  81. public function validateAccessToken($accessToken);
  82. /**
  83. * Perform basic validation of an Oauth token, of any type (e.g. request, access, etc.).
  84. *
  85. * @param string $oauthToken The token string.
  86. * @return bool True if the Oauth token passes basic validation.
  87. */
  88. public function validateOauthToken($oauthToken);
  89. /**
  90. * Retrieve a consumer given the consumer's key.
  91. *
  92. * @param string $consumerKey The 'oauth_consumer_key' value.
  93. * @return ConsumerInterface
  94. * @throws \Magento\Framework\Oauth\Exception
  95. */
  96. public function getConsumerByKey($consumerKey);
  97. }