summaryrefslogtreecommitdiffstats
path: root/core/Controller/AppPasswordController.php
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2019-05-17 09:51:47 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2019-05-17 09:52:06 +0200
commit2dcb4cfbd644babf0ee202b4489689d882ae1dd3 (patch)
treeacb0f85eed9cae44dc47af99d243387100651f74 /core/Controller/AppPasswordController.php
parente625164e85b3ab4be3a51b86f909564430cb388b (diff)
downloadnextcloud-server-2dcb4cfbd644babf0ee202b4489689d882ae1dd3.tar.gz
nextcloud-server-2dcb4cfbd644babf0ee202b4489689d882ae1dd3.zip
Allow clients to delete their own apptoken
Fixes #15480 Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'core/Controller/AppPasswordController.php')
-rw-r--r--core/Controller/AppPasswordController.php23
1 files changed, 23 insertions, 0 deletions
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();
+ }
}