TokenHandler.php 792 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. /**
  17. * TokenHandler constructor.
  18. *
  19. * @param ISecureRandom $secureRandom
  20. */
  21. public function __construct(
  22. private ISecureRandom $secureRandom,
  23. ) {
  24. }
  25. /**
  26. * generate to token used to authenticate federated shares
  27. *
  28. * @return string
  29. */
  30. public function generateToken() {
  31. $token = $this->secureRandom->generate(
  32. self::TOKEN_LENGTH,
  33. ISecureRandom::CHAR_ALPHANUMERIC);
  34. return $token;
  35. }
  36. }