2016-02-04 03:59:52 -05:00
|
|
|
<?php
|
2024-05-28 10:42:42 -04:00
|
|
|
|
2016-02-04 03:59:52 -05:00
|
|
|
/**
|
2024-05-28 10:42:42 -04:00
|
|
|
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2016-02-04 03:59:52 -05:00
|
|
|
*/
|
|
|
|
|
namespace OCA\FederatedFileSharing;
|
|
|
|
|
|
|
|
|
|
use OCP\Security\ISecureRandom;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class TokenHandler
|
|
|
|
|
*
|
|
|
|
|
* @package OCA\FederatedFileSharing
|
|
|
|
|
*/
|
|
|
|
|
class TokenHandler {
|
2020-04-10 10:54:27 -04:00
|
|
|
public const TOKEN_LENGTH = 15;
|
2016-02-04 03:59:52 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* TokenHandler constructor.
|
|
|
|
|
*
|
|
|
|
|
* @param ISecureRandom $secureRandom
|
|
|
|
|
*/
|
2024-10-18 06:04:22 -04:00
|
|
|
public function __construct(
|
|
|
|
|
private ISecureRandom $secureRandom,
|
|
|
|
|
) {
|
2016-02-04 03:59:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* generate to token used to authenticate federated shares
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function generateToken() {
|
|
|
|
|
$token = $this->secureRandom->generate(
|
|
|
|
|
self::TOKEN_LENGTH,
|
2021-07-07 11:52:46 -04:00
|
|
|
ISecureRandom::CHAR_ALPHANUMERIC);
|
2016-02-04 03:59:52 -05:00
|
|
|
return $token;
|
|
|
|
|
}
|
|
|
|
|
}
|