From f94fb33062bf3a10e5b0b2023194ad55ce18c3fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Fri, 20 Oct 2023 17:51:33 +0200 Subject: [PATCH 1/9] Move IToken and IProvider::getToken to OCP MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- lib/composer/composer/autoload_classmap.php | 1 + lib/composer/composer/autoload_static.php | 1 + lib/private/Authentication/Token/IToken.php | 106 +-------------- lib/public/Authentication/Token/IProvider.php | 11 ++ lib/public/Authentication/Token/IToken.php | 124 ++++++++++++++++++ 5 files changed, 139 insertions(+), 104 deletions(-) create mode 100644 lib/public/Authentication/Token/IToken.php diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 9d0570d349c6d..6411a9517469d 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -113,6 +113,7 @@ 'OCP\\Authentication\\LoginCredentials\\ICredentials' => $baseDir . '/lib/public/Authentication/LoginCredentials/ICredentials.php', 'OCP\\Authentication\\LoginCredentials\\IStore' => $baseDir . '/lib/public/Authentication/LoginCredentials/IStore.php', 'OCP\\Authentication\\Token\\IProvider' => $baseDir . '/lib/public/Authentication/Token/IProvider.php', + 'OCP\\Authentication\\Token\\IToken' => $baseDir . '/lib/public/Authentication/Token/IToken.php', 'OCP\\Authentication\\TwoFactorAuth\\ALoginSetupController' => $baseDir . '/lib/public/Authentication/TwoFactorAuth/ALoginSetupController.php', 'OCP\\Authentication\\TwoFactorAuth\\IActivatableAtLogin' => $baseDir . '/lib/public/Authentication/TwoFactorAuth/IActivatableAtLogin.php', 'OCP\\Authentication\\TwoFactorAuth\\IActivatableByAdmin' => $baseDir . '/lib/public/Authentication/TwoFactorAuth/IActivatableByAdmin.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 63ad21216a4a6..842e9ca0d9f04 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -146,6 +146,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OCP\\Authentication\\LoginCredentials\\ICredentials' => __DIR__ . '/../../..' . '/lib/public/Authentication/LoginCredentials/ICredentials.php', 'OCP\\Authentication\\LoginCredentials\\IStore' => __DIR__ . '/../../..' . '/lib/public/Authentication/LoginCredentials/IStore.php', 'OCP\\Authentication\\Token\\IProvider' => __DIR__ . '/../../..' . '/lib/public/Authentication/Token/IProvider.php', + 'OCP\\Authentication\\Token\\IToken' => __DIR__ . '/../../..' . '/lib/public/Authentication/Token/IToken.php', 'OCP\\Authentication\\TwoFactorAuth\\ALoginSetupController' => __DIR__ . '/../../..' . '/lib/public/Authentication/TwoFactorAuth/ALoginSetupController.php', 'OCP\\Authentication\\TwoFactorAuth\\IActivatableAtLogin' => __DIR__ . '/../../..' . '/lib/public/Authentication/TwoFactorAuth/IActivatableAtLogin.php', 'OCP\\Authentication\\TwoFactorAuth\\IActivatableByAdmin' => __DIR__ . '/../../..' . '/lib/public/Authentication/TwoFactorAuth/IActivatableByAdmin.php', diff --git a/lib/private/Authentication/Token/IToken.php b/lib/private/Authentication/Token/IToken.php index 5ca4eaea84372..e8c3b638b9f36 100644 --- a/lib/private/Authentication/Token/IToken.php +++ b/lib/private/Authentication/Token/IToken.php @@ -26,109 +26,7 @@ */ namespace OC\Authentication\Token; -use JsonSerializable; +use OCP\Authentication\Token\IToken as OCPIToken; -interface IToken extends JsonSerializable { - public const TEMPORARY_TOKEN = 0; - public const PERMANENT_TOKEN = 1; - public const WIPE_TOKEN = 2; - public const DO_NOT_REMEMBER = 0; - public const REMEMBER = 1; - - /** - * Get the token ID - * - * @return int - */ - public function getId(): int; - - /** - * Get the user UID - * - * @return string - */ - public function getUID(): string; - - /** - * Get the login name used when generating the token - * - * @return string - */ - public function getLoginName(): string; - - /** - * Get the (encrypted) login password - * - * @return string|null - */ - public function getPassword(); - - /** - * Get the timestamp of the last password check - * - * @return int - */ - public function getLastCheck(): int; - - /** - * Set the timestamp of the last password check - * - * @param int $time - */ - public function setLastCheck(int $time); - - /** - * Get the authentication scope for this token - * - * @return string - */ - public function getScope(): string; - - /** - * Get the authentication scope for this token - * - * @return array - */ - public function getScopeAsArray(): array; - - /** - * Set the authentication scope for this token - * - * @param array $scope - */ - public function setScope($scope); - - /** - * Get the name of the token - * @return string - */ - public function getName(): string; - - /** - * Get the remember state of the token - * - * @return int - */ - public function getRemember(): int; - - /** - * Set the token - * - * @param string $token - */ - public function setToken(string $token); - - /** - * Set the password - * - * @param string $password - */ - public function setPassword(string $password); - - /** - * Set the expiration time of the token - * - * @param int|null $expires - */ - public function setExpires($expires); +interface IToken extends OCPIToken { } diff --git a/lib/public/Authentication/Token/IProvider.php b/lib/public/Authentication/Token/IProvider.php index da2e400eb79ec..4c324d685b729 100644 --- a/lib/public/Authentication/Token/IProvider.php +++ b/lib/public/Authentication/Token/IProvider.php @@ -38,4 +38,15 @@ interface IProvider { * @return void */ public function invalidateTokensOfUser(string $uid, ?string $clientName); + + /** + * Get a token by token string id + * + * @since 28.0.0 + * @throws InvalidTokenException + * @throws ExpiredTokenException + * @throws WipeTokenException + * @return IToken + */ + public function getToken(string $tokenId): IToken; } diff --git a/lib/public/Authentication/Token/IToken.php b/lib/public/Authentication/Token/IToken.php new file mode 100644 index 0000000000000..e6161f3b14cda --- /dev/null +++ b/lib/public/Authentication/Token/IToken.php @@ -0,0 +1,124 @@ + + * @author Robin Appelman + * @author Roeland Jago Douma + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ +namespace OCP\Authentication\Token; + +use JsonSerializable; + +/** + * @since 28.0.0 + */ +interface IToken extends JsonSerializable { + public const TEMPORARY_TOKEN = 0; + public const PERMANENT_TOKEN = 1; + public const WIPE_TOKEN = 2; + public const DO_NOT_REMEMBER = 0; + public const REMEMBER = 1; + + /** + * Get the token ID + * @since 28.0.0 + */ + public function getId(): int; + + /** + * Get the user UID + * @since 28.0.0 + */ + public function getUID(): string; + + /** + * Get the login name used when generating the token + * @since 28.0.0 + */ + public function getLoginName(): string; + + /** + * Get the (encrypted) login password + * @since 28.0.0 + */ + public function getPassword(): ?string; + + /** + * Get the timestamp of the last password check + * @since 28.0.0 + */ + public function getLastCheck(): int; + + /** + * Set the timestamp of the last password check + * @since 28.0.0 + */ + public function setLastCheck(int $time): void; + + /** + * Get the authentication scope for this token + * @since 28.0.0 + */ + public function getScope(): string; + + /** + * Get the authentication scope for this token + * @since 28.0.0 + */ + public function getScopeAsArray(): array; + + /** + * Set the authentication scope for this token + * @since 28.0.0 + */ + public function setScope(array $scope): void; + + /** + * Get the name of the token + * @since 28.0.0 + */ + public function getName(): string; + + /** + * Get the remember state of the token + * @since 28.0.0 + */ + public function getRemember(): int; + + /** + * Set the token + * @since 28.0.0 + */ + public function setToken(string $token): void; + + /** + * Set the password + * @since 28.0.0 + */ + public function setPassword(string $password): void; + + /** + * Set the expiration time of the token + * @since 28.0.0 + */ + public function setExpires(?int $expires): void; +} From 356f0291a2b6ae536b00b19b6a551d2d4bad8c12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Mon, 23 Oct 2023 09:41:32 +0200 Subject: [PATCH 2/9] Align PublicKeyToken with interface changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- .../Authentication/Token/PublicKeyToken.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/private/Authentication/Token/PublicKeyToken.php b/lib/private/Authentication/Token/PublicKeyToken.php index 45335e17c3161..0f2a515aa0d20 100644 --- a/lib/private/Authentication/Token/PublicKeyToken.php +++ b/lib/private/Authentication/Token/PublicKeyToken.php @@ -137,10 +137,8 @@ public function getLoginName(): string { /** * Get the (encrypted) login password - * - * @return string|null */ - public function getPassword() { + public function getPassword(): ?string { return parent::getPassword(); } @@ -165,10 +163,8 @@ public function getLastCheck(): int { /** * Get the timestamp of the last password check - * - * @param int $time */ - public function setLastCheck(int $time) { + public function setLastCheck(int $time): void { parent::setLastCheck($time); } @@ -191,7 +187,7 @@ public function getScopeAsArray(): array { return $scope; } - public function setScope($scope) { + public function setScope(mixed $scope): void { if (is_array($scope)) { parent::setScope(json_encode($scope)); } else { @@ -211,15 +207,15 @@ public function getRemember(): int { return parent::getRemember(); } - public function setToken(string $token) { + public function setToken(string $token): void { parent::setToken($token); } - public function setPassword(string $password = null) { + public function setPassword(string $password = null): void { parent::setPassword($password); } - public function setExpires($expires) { + public function setExpires($expires): void { parent::setExpires($expires); } From 16b9373b82ccfe9a0982f4678c16a19298014e27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Mon, 23 Oct 2023 10:17:34 +0200 Subject: [PATCH 3/9] Adapt baseline to filename change MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- build/psalm-baseline.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/psalm-baseline.xml b/build/psalm-baseline.xml index b54f19b8ee31c..8a2c728ab5b4b 100644 --- a/build/psalm-baseline.xml +++ b/build/psalm-baseline.xml @@ -2080,7 +2080,7 @@ $trySession - + DO_NOT_REMEMBER PERMANENT_TOKEN From b82e25ea7a13e98212201a905718309a3d1415ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Mon, 23 Oct 2023 10:18:20 +0200 Subject: [PATCH 4/9] Move Exceptions used in OCP to OCP MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- .../Exceptions/ExpiredTokenException.php | 19 ++------- .../Exceptions/InvalidTokenException.php | 7 ++-- .../Exceptions/WipeTokenException.php | 19 ++------- .../Exceptions/ExpiredTokenException.php | 40 +++++++++++++++++++ .../Exceptions/InvalidTokenException.php | 30 ++++++++++++++ .../Exceptions/WipeTokenException.php | 40 +++++++++++++++++++ lib/public/Authentication/Token/IProvider.php | 4 ++ 7 files changed, 126 insertions(+), 33 deletions(-) create mode 100644 lib/public/Authentication/Exceptions/ExpiredTokenException.php create mode 100644 lib/public/Authentication/Exceptions/InvalidTokenException.php create mode 100644 lib/public/Authentication/Exceptions/WipeTokenException.php diff --git a/lib/private/Authentication/Exceptions/ExpiredTokenException.php b/lib/private/Authentication/Exceptions/ExpiredTokenException.php index 0dc92b4592051..c23a1176faef5 100644 --- a/lib/private/Authentication/Exceptions/ExpiredTokenException.php +++ b/lib/private/Authentication/Exceptions/ExpiredTokenException.php @@ -25,19 +25,8 @@ */ namespace OC\Authentication\Exceptions; -use OC\Authentication\Token\IToken; - -class ExpiredTokenException extends InvalidTokenException { - /** @var IToken */ - private $token; - - public function __construct(IToken $token) { - parent::__construct(); - - $this->token = $token; - } - - public function getToken(): IToken { - return $this->token; - } +/** + * @deprecated 28.0.0 use OCP version instead + */ +class ExpiredTokenException extends \OCP\Authentication\Exceptions\ExpiredTokenException { } diff --git a/lib/private/Authentication/Exceptions/InvalidTokenException.php b/lib/private/Authentication/Exceptions/InvalidTokenException.php index acaabff6b88a7..7de6e1522fac5 100644 --- a/lib/private/Authentication/Exceptions/InvalidTokenException.php +++ b/lib/private/Authentication/Exceptions/InvalidTokenException.php @@ -24,7 +24,8 @@ */ namespace OC\Authentication\Exceptions; -use Exception; - -class InvalidTokenException extends Exception { +/** + * @deprecated 28.0.0 use OCP version instead + */ +class InvalidTokenException extends \OCP\Authentication\Exceptions\InvalidTokenException { } diff --git a/lib/private/Authentication/Exceptions/WipeTokenException.php b/lib/private/Authentication/Exceptions/WipeTokenException.php index 1c60ab9da78ee..8ae4f74e4d795 100644 --- a/lib/private/Authentication/Exceptions/WipeTokenException.php +++ b/lib/private/Authentication/Exceptions/WipeTokenException.php @@ -25,19 +25,8 @@ */ namespace OC\Authentication\Exceptions; -use OC\Authentication\Token\IToken; - -class WipeTokenException extends InvalidTokenException { - /** @var IToken */ - private $token; - - public function __construct(IToken $token) { - parent::__construct(); - - $this->token = $token; - } - - public function getToken(): IToken { - return $this->token; - } +/** + * @deprecated 28.0.0 use OCP version instead + */ +class WipeTokenException extends \OCP\Authentication\Exceptions\WipeTokenException { } diff --git a/lib/public/Authentication/Exceptions/ExpiredTokenException.php b/lib/public/Authentication/Exceptions/ExpiredTokenException.php new file mode 100644 index 0000000000000..eab68ba4eff58 --- /dev/null +++ b/lib/public/Authentication/Exceptions/ExpiredTokenException.php @@ -0,0 +1,40 @@ + + * + * @author Roeland Jago Douma + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ +namespace OCP\Authentication\Exceptions; + +use OCP\Authentication\Token\IToken; + +class ExpiredTokenException extends InvalidTokenException { + public function __construct( + private IToken $token, + ) { + parent::__construct(); + } + + public function getToken(): IToken { + return $this->token; + } +} diff --git a/lib/public/Authentication/Exceptions/InvalidTokenException.php b/lib/public/Authentication/Exceptions/InvalidTokenException.php new file mode 100644 index 0000000000000..2556e191d630a --- /dev/null +++ b/lib/public/Authentication/Exceptions/InvalidTokenException.php @@ -0,0 +1,30 @@ + + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ +namespace OCP\Authentication\Exceptions; + +use Exception; + +class InvalidTokenException extends Exception { +} diff --git a/lib/public/Authentication/Exceptions/WipeTokenException.php b/lib/public/Authentication/Exceptions/WipeTokenException.php new file mode 100644 index 0000000000000..aa2da6739e63e --- /dev/null +++ b/lib/public/Authentication/Exceptions/WipeTokenException.php @@ -0,0 +1,40 @@ + + * + * @author Roeland Jago Douma + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ +namespace OCP\Authentication\Exceptions; + +use OCP\Authentication\Token\IToken; + +class WipeTokenException extends InvalidTokenException { + public function __construct( + private IToken $token, + ) { + parent::__construct(); + } + + public function getToken(): IToken { + return $this->token; + } +} diff --git a/lib/public/Authentication/Token/IProvider.php b/lib/public/Authentication/Token/IProvider.php index 4c324d685b729..59d2b8f3649ce 100644 --- a/lib/public/Authentication/Token/IProvider.php +++ b/lib/public/Authentication/Token/IProvider.php @@ -24,6 +24,10 @@ */ namespace OCP\Authentication\Token; +use OCP\Authentication\Exceptions\ExpiredTokenException; +use OCP\Authentication\Exceptions\InvalidTokenException; +use OCP\Authentication\Exceptions\WipeTokenException; + /** * @since 24.0.8 */ From 1bdf952fdeab6305785cae3522eb4807c0e68c99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Mon, 23 Oct 2023 10:57:26 +0200 Subject: [PATCH 5/9] Make sure that OC interfaces returns OC interfaces for backward compatibility MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- .../lib/Controller/AuthSettingsController.php | 3 +-- .../Exceptions/ExpiredTokenException.php | 13 +++++++++++++ .../Exceptions/WipeTokenException.php | 13 +++++++++++++ .../Exceptions/ExpiredTokenException.php | 9 +++++++++ .../Exceptions/InvalidTokenException.php | 3 +++ .../Exceptions/WipeTokenException.php | 9 +++++++++ 6 files changed, 48 insertions(+), 2 deletions(-) diff --git a/apps/settings/lib/Controller/AuthSettingsController.php b/apps/settings/lib/Controller/AuthSettingsController.php index 38db7be1e9187..305908e5e0a74 100644 --- a/apps/settings/lib/Controller/AuthSettingsController.php +++ b/apps/settings/lib/Controller/AuthSettingsController.php @@ -53,14 +53,13 @@ use Psr\Log\LoggerInterface; class AuthSettingsController extends Controller { - /** @var IProvider */ private $tokenProvider; /** @var ISession */ private $session; - /** IUserSession */ + /** @var IUserSession */ private $userSession; /** @var string */ diff --git a/lib/private/Authentication/Exceptions/ExpiredTokenException.php b/lib/private/Authentication/Exceptions/ExpiredTokenException.php index c23a1176faef5..18618a557f3c2 100644 --- a/lib/private/Authentication/Exceptions/ExpiredTokenException.php +++ b/lib/private/Authentication/Exceptions/ExpiredTokenException.php @@ -25,8 +25,21 @@ */ namespace OC\Authentication\Exceptions; +use OC\Authentication\Token\IToken; + /** * @deprecated 28.0.0 use OCP version instead */ class ExpiredTokenException extends \OCP\Authentication\Exceptions\ExpiredTokenException { + public function __construct( + IToken $token, + ) { + parent::__construct($token); + } + + public function getToken(): IToken { + $token = parent::getToken(); + /** @var IToken $token We know that we passed OC interface from constructor */ + return $token; + } } diff --git a/lib/private/Authentication/Exceptions/WipeTokenException.php b/lib/private/Authentication/Exceptions/WipeTokenException.php index 8ae4f74e4d795..9b24ca2443021 100644 --- a/lib/private/Authentication/Exceptions/WipeTokenException.php +++ b/lib/private/Authentication/Exceptions/WipeTokenException.php @@ -25,8 +25,21 @@ */ namespace OC\Authentication\Exceptions; +use OC\Authentication\Token\IToken; + /** * @deprecated 28.0.0 use OCP version instead */ class WipeTokenException extends \OCP\Authentication\Exceptions\WipeTokenException { + public function __construct( + IToken $token, + ) { + parent::__construct($token); + } + + public function getToken(): IToken { + $token = parent::getToken(); + /** @var IToken $token We know that we passed OC interface from constructor */ + return $token; + } } diff --git a/lib/public/Authentication/Exceptions/ExpiredTokenException.php b/lib/public/Authentication/Exceptions/ExpiredTokenException.php index eab68ba4eff58..58f2f22d5c723 100644 --- a/lib/public/Authentication/Exceptions/ExpiredTokenException.php +++ b/lib/public/Authentication/Exceptions/ExpiredTokenException.php @@ -27,13 +27,22 @@ use OCP\Authentication\Token\IToken; +/** + * @since 28.0 + */ class ExpiredTokenException extends InvalidTokenException { + /** + * @since 28.0 + */ public function __construct( private IToken $token, ) { parent::__construct(); } + /** + * @since 28.0 + */ public function getToken(): IToken { return $this->token; } diff --git a/lib/public/Authentication/Exceptions/InvalidTokenException.php b/lib/public/Authentication/Exceptions/InvalidTokenException.php index 2556e191d630a..7d55694d3ea8c 100644 --- a/lib/public/Authentication/Exceptions/InvalidTokenException.php +++ b/lib/public/Authentication/Exceptions/InvalidTokenException.php @@ -26,5 +26,8 @@ use Exception; +/** + * @since 28.0 + */ class InvalidTokenException extends Exception { } diff --git a/lib/public/Authentication/Exceptions/WipeTokenException.php b/lib/public/Authentication/Exceptions/WipeTokenException.php index aa2da6739e63e..9e80432ef522d 100644 --- a/lib/public/Authentication/Exceptions/WipeTokenException.php +++ b/lib/public/Authentication/Exceptions/WipeTokenException.php @@ -27,13 +27,22 @@ use OCP\Authentication\Token\IToken; +/** + * @since 28.0 + */ class WipeTokenException extends InvalidTokenException { + /** + * @since 28.0 + */ public function __construct( private IToken $token, ) { parent::__construct(); } + /** + * @since 28.0 + */ public function getToken(): IToken { return $this->token; } From 7a6c4ecc2562479381a7766c2538cb2d9257e9b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Mon, 23 Oct 2023 11:47:48 +0200 Subject: [PATCH 6/9] Update autoloaders MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- lib/composer/composer/autoload_classmap.php | 3 +++ lib/composer/composer/autoload_static.php | 3 +++ 2 files changed, 6 insertions(+) diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 6411a9517469d..2c1b4fa58b712 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -106,7 +106,10 @@ 'OCP\\Authentication\\Events\\AnyLoginFailedEvent' => $baseDir . '/lib/public/Authentication/Events/AnyLoginFailedEvent.php', 'OCP\\Authentication\\Events\\LoginFailedEvent' => $baseDir . '/lib/public/Authentication/Events/LoginFailedEvent.php', 'OCP\\Authentication\\Exceptions\\CredentialsUnavailableException' => $baseDir . '/lib/public/Authentication/Exceptions/CredentialsUnavailableException.php', + 'OCP\\Authentication\\Exceptions\\ExpiredTokenException' => $baseDir . '/lib/public/Authentication/Exceptions/ExpiredTokenException.php', + 'OCP\\Authentication\\Exceptions\\InvalidTokenException' => $baseDir . '/lib/public/Authentication/Exceptions/InvalidTokenException.php', 'OCP\\Authentication\\Exceptions\\PasswordUnavailableException' => $baseDir . '/lib/public/Authentication/Exceptions/PasswordUnavailableException.php', + 'OCP\\Authentication\\Exceptions\\WipeTokenException' => $baseDir . '/lib/public/Authentication/Exceptions/WipeTokenException.php', 'OCP\\Authentication\\IAlternativeLogin' => $baseDir . '/lib/public/Authentication/IAlternativeLogin.php', 'OCP\\Authentication\\IApacheBackend' => $baseDir . '/lib/public/Authentication/IApacheBackend.php', 'OCP\\Authentication\\IProvideUserSecretBackend' => $baseDir . '/lib/public/Authentication/IProvideUserSecretBackend.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 842e9ca0d9f04..8264df66e09cb 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -139,7 +139,10 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OCP\\Authentication\\Events\\AnyLoginFailedEvent' => __DIR__ . '/../../..' . '/lib/public/Authentication/Events/AnyLoginFailedEvent.php', 'OCP\\Authentication\\Events\\LoginFailedEvent' => __DIR__ . '/../../..' . '/lib/public/Authentication/Events/LoginFailedEvent.php', 'OCP\\Authentication\\Exceptions\\CredentialsUnavailableException' => __DIR__ . '/../../..' . '/lib/public/Authentication/Exceptions/CredentialsUnavailableException.php', + 'OCP\\Authentication\\Exceptions\\ExpiredTokenException' => __DIR__ . '/../../..' . '/lib/public/Authentication/Exceptions/ExpiredTokenException.php', + 'OCP\\Authentication\\Exceptions\\InvalidTokenException' => __DIR__ . '/../../..' . '/lib/public/Authentication/Exceptions/InvalidTokenException.php', 'OCP\\Authentication\\Exceptions\\PasswordUnavailableException' => __DIR__ . '/../../..' . '/lib/public/Authentication/Exceptions/PasswordUnavailableException.php', + 'OCP\\Authentication\\Exceptions\\WipeTokenException' => __DIR__ . '/../../..' . '/lib/public/Authentication/Exceptions/WipeTokenException.php', 'OCP\\Authentication\\IAlternativeLogin' => __DIR__ . '/../../..' . '/lib/public/Authentication/IAlternativeLogin.php', 'OCP\\Authentication\\IApacheBackend' => __DIR__ . '/../../..' . '/lib/public/Authentication/IApacheBackend.php', 'OCP\\Authentication\\IProvideUserSecretBackend' => __DIR__ . '/../../..' . '/lib/public/Authentication/IProvideUserSecretBackend.php', From 58a57a714e0875d15da6513aecb6737bb3c603b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Mon, 23 Oct 2023 15:19:38 +0200 Subject: [PATCH 7/9] Use more precise typing for setScope method parameter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- lib/private/Authentication/Token/PublicKeyToken.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/private/Authentication/Token/PublicKeyToken.php b/lib/private/Authentication/Token/PublicKeyToken.php index 0f2a515aa0d20..198990cdd950b 100644 --- a/lib/private/Authentication/Token/PublicKeyToken.php +++ b/lib/private/Authentication/Token/PublicKeyToken.php @@ -187,11 +187,11 @@ public function getScopeAsArray(): array { return $scope; } - public function setScope(mixed $scope): void { + public function setScope(string|array $scope): void { if (is_array($scope)) { parent::setScope(json_encode($scope)); } else { - parent::setScope((string)$scope); + parent::setScope($scope); } } From 33a24134a7cb6b7af08a097a5807c58888cba8c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Mon, 23 Oct 2023 15:20:04 +0200 Subject: [PATCH 8/9] Improve docblock annotations for tokens and their exceptions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- .../Exceptions/ExpiredTokenException.php | 2 +- .../Exceptions/WipeTokenException.php | 2 +- lib/private/Authentication/Token/IToken.php | 3 +++ .../Exceptions/ExpiredTokenException.php | 6 +++--- .../Exceptions/InvalidTokenException.php | 2 +- .../Exceptions/WipeTokenException.php | 6 +++--- lib/public/Authentication/Token/IToken.php | 15 +++++++++++++++ 7 files changed, 27 insertions(+), 9 deletions(-) diff --git a/lib/private/Authentication/Exceptions/ExpiredTokenException.php b/lib/private/Authentication/Exceptions/ExpiredTokenException.php index 18618a557f3c2..15069313712e2 100644 --- a/lib/private/Authentication/Exceptions/ExpiredTokenException.php +++ b/lib/private/Authentication/Exceptions/ExpiredTokenException.php @@ -28,7 +28,7 @@ use OC\Authentication\Token\IToken; /** - * @deprecated 28.0.0 use OCP version instead + * @deprecated 28.0.0 use {@see \OCP\Authentication\Exceptions\ExpiredTokenException} instead */ class ExpiredTokenException extends \OCP\Authentication\Exceptions\ExpiredTokenException { public function __construct( diff --git a/lib/private/Authentication/Exceptions/WipeTokenException.php b/lib/private/Authentication/Exceptions/WipeTokenException.php index 9b24ca2443021..25b7cb74359c2 100644 --- a/lib/private/Authentication/Exceptions/WipeTokenException.php +++ b/lib/private/Authentication/Exceptions/WipeTokenException.php @@ -28,7 +28,7 @@ use OC\Authentication\Token\IToken; /** - * @deprecated 28.0.0 use OCP version instead + * @deprecated 28.0.0 use {@see \OCP\Authentication\Exceptions\WipeTokenException} instead */ class WipeTokenException extends \OCP\Authentication\Exceptions\WipeTokenException { public function __construct( diff --git a/lib/private/Authentication/Token/IToken.php b/lib/private/Authentication/Token/IToken.php index e8c3b638b9f36..eb172f3339602 100644 --- a/lib/private/Authentication/Token/IToken.php +++ b/lib/private/Authentication/Token/IToken.php @@ -28,5 +28,8 @@ use OCP\Authentication\Token\IToken as OCPIToken; +/** + * @deprecated 28.0.0 use {@see \OCP\Authentication\Token\IToken} instead + */ interface IToken extends OCPIToken { } diff --git a/lib/public/Authentication/Exceptions/ExpiredTokenException.php b/lib/public/Authentication/Exceptions/ExpiredTokenException.php index 58f2f22d5c723..5c1f4a30541ca 100644 --- a/lib/public/Authentication/Exceptions/ExpiredTokenException.php +++ b/lib/public/Authentication/Exceptions/ExpiredTokenException.php @@ -28,11 +28,11 @@ use OCP\Authentication\Token\IToken; /** - * @since 28.0 + * @since 28.0.0 */ class ExpiredTokenException extends InvalidTokenException { /** - * @since 28.0 + * @since 28.0.0 */ public function __construct( private IToken $token, @@ -41,7 +41,7 @@ public function __construct( } /** - * @since 28.0 + * @since 28.0.0 */ public function getToken(): IToken { return $this->token; diff --git a/lib/public/Authentication/Exceptions/InvalidTokenException.php b/lib/public/Authentication/Exceptions/InvalidTokenException.php index 7d55694d3ea8c..4869cbd64659f 100644 --- a/lib/public/Authentication/Exceptions/InvalidTokenException.php +++ b/lib/public/Authentication/Exceptions/InvalidTokenException.php @@ -27,7 +27,7 @@ use Exception; /** - * @since 28.0 + * @since 28.0.0 */ class InvalidTokenException extends Exception { } diff --git a/lib/public/Authentication/Exceptions/WipeTokenException.php b/lib/public/Authentication/Exceptions/WipeTokenException.php index 9e80432ef522d..81ea2dc57ad7d 100644 --- a/lib/public/Authentication/Exceptions/WipeTokenException.php +++ b/lib/public/Authentication/Exceptions/WipeTokenException.php @@ -28,11 +28,11 @@ use OCP\Authentication\Token\IToken; /** - * @since 28.0 + * @since 28.0.0 */ class WipeTokenException extends InvalidTokenException { /** - * @since 28.0 + * @since 28.0.0 */ public function __construct( private IToken $token, @@ -41,7 +41,7 @@ public function __construct( } /** - * @since 28.0 + * @since 28.0.0 */ public function getToken(): IToken { return $this->token; diff --git a/lib/public/Authentication/Token/IToken.php b/lib/public/Authentication/Token/IToken.php index e6161f3b14cda..7b6ce8327c60b 100644 --- a/lib/public/Authentication/Token/IToken.php +++ b/lib/public/Authentication/Token/IToken.php @@ -32,10 +32,25 @@ * @since 28.0.0 */ interface IToken extends JsonSerializable { + /** + * @since 28.0.0 + */ public const TEMPORARY_TOKEN = 0; + /** + * @since 28.0.0 + */ public const PERMANENT_TOKEN = 1; + /** + * @since 28.0.0 + */ public const WIPE_TOKEN = 2; + /** + * @since 28.0.0 + */ public const DO_NOT_REMEMBER = 0; + /** + * @since 28.0.0 + */ public const REMEMBER = 1; /** From d8b42c613164c1155082127e3644767c6be601f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Mon, 23 Oct 2023 15:52:07 +0200 Subject: [PATCH 9/9] Allow passing null to PublicKeyToken::setScope, fixes tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- lib/private/Authentication/Token/PublicKeyToken.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/private/Authentication/Token/PublicKeyToken.php b/lib/private/Authentication/Token/PublicKeyToken.php index 198990cdd950b..b77a856589de8 100644 --- a/lib/private/Authentication/Token/PublicKeyToken.php +++ b/lib/private/Authentication/Token/PublicKeyToken.php @@ -187,11 +187,11 @@ public function getScopeAsArray(): array { return $scope; } - public function setScope(string|array $scope): void { + public function setScope(array|string|null $scope): void { if (is_array($scope)) { parent::setScope(json_encode($scope)); } else { - parent::setScope($scope); + parent::setScope((string)$scope); } }