NonceGeneratorInterface.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. * NonceGeneratorInterface provides methods for generating a nonce for a consumer and validating a nonce to ensure
  9. * that it is not already used by an existing consumer. Validation will persist the nonce if validation succeeds.
  10. * A method for generating a current timestamp is also provided by this interface.
  11. *
  12. * @api
  13. * @since 100.0.2
  14. */
  15. interface NonceGeneratorInterface
  16. {
  17. /**
  18. * Generate a new nonce for the consumer (if consumer is specified).
  19. *
  20. * @param ConsumerInterface $consumer
  21. * @return string The generated nonce value.
  22. */
  23. public function generateNonce(ConsumerInterface $consumer = null);
  24. /**
  25. * Generate a current timestamp.
  26. *
  27. * @return int The time as an int
  28. */
  29. public function generateTimestamp();
  30. /**
  31. * Validate the specified nonce, which ensures that it can only be used by a single consumer and persist it
  32. * with the specified consumer and timestamp. This method effectively saves the nonce and marks it as used
  33. * by the specified consumer.
  34. *
  35. * @param ConsumerInterface $consumer
  36. * @param string $nonce The nonce value.
  37. * @param int $timestamp The 'oauth_timestamp' value.
  38. * @return void
  39. * @throws \Magento\Framework\Oauth\Exception Exceptions are thrown for validation errors.
  40. */
  41. public function validateNonce(ConsumerInterface $consumer, $nonce, $timestamp);
  42. }