From 2dcb4cfbd644babf0ee202b4489689d882ae1dd3 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Fri, 17 May 2019 09:51:47 +0200 Subject: Allow clients to delete their own apptoken Fixes #15480 Signed-off-by: Roeland Jago Douma --- core/Controller/AppPasswordController.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'core/Controller/AppPasswordController.php') diff --git a/core/Controller/AppPasswordController.php b/core/Controller/AppPasswordController.php index a858bb025d9..01ca1e2597b 100644 --- a/core/Controller/AppPasswordController.php +++ b/core/Controller/AppPasswordController.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace OC\Core\Controller; +use OC\Authentication\Exceptions\InvalidTokenException; use OC\Authentication\Token\IProvider; use OC\Authentication\Token\IToken; use OCP\AppFramework\Http\DataResponse; @@ -115,4 +116,26 @@ class AppPasswordController extends \OCP\AppFramework\OCSController { 'apppassword' => $token ]); } + + /** + * @NoAdminRequired + * + * @return DataResponse + */ + public function deleteAppPassword() { + if (!$this->session->exists('app_password')) { + throw new OCSForbiddenException('no app password in use'); + } + + $appPassword = $this->session->get('app_password'); + + try { + $token = $this->tokenProvider->getToken($appPassword); + } catch (InvalidTokenException $e) { + throw new OCSForbiddenException('could not remove apptoken'); + } + + $this->tokenProvider->invalidateTokenById($token->getUID(), $token->getId()); + return new DataResponse(); + } } -- cgit v1.2.3