1
0

TokenHandler.php 869 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\FederatedFileSharing;
  8. use OCP\Security\ISecureRandom;
  9. /**
  10. * Class TokenHandler
  11. *
  12. * @package OCA\FederatedFileSharing
  13. */
  14. class TokenHandler {
  15. public const TOKEN_LENGTH = 15;
  16. /** @var ISecureRandom */
  17. private $secureRandom;
  18. /**
  19. * TokenHandler constructor.
  20. *
  21. * @param ISecureRandom $secureRandom
  22. */
  23. public function __construct(ISecureRandom $secureRandom) {
  24. $this->secureRandom = $secureRandom;
  25. }
  26. /**
  27. * generate to token used to authenticate federated shares
  28. *
  29. * @return string
  30. */
  31. public function generateToken() {
  32. $token = $this->secureRandom->generate(
  33. self::TOKEN_LENGTH,
  34. ISecureRandom::CHAR_ALPHANUMERIC);
  35. return $token;
  36. }
  37. }