diff options
Diffstat (limited to 'core/Controller/AppPasswordController.php')
-rw-r--r-- | core/Controller/AppPasswordController.php | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/core/Controller/AppPasswordController.php b/core/Controller/AppPasswordController.php index 01ca1e2597b..a66acb3c5f3 100644 --- a/core/Controller/AppPasswordController.php +++ b/core/Controller/AppPasswordController.php @@ -138,4 +138,28 @@ class AppPasswordController extends \OCP\AppFramework\OCSController { $this->tokenProvider->invalidateTokenById($token->getUID(), $token->getId()); return new DataResponse(); } + + /** + * @NoAdminRequired + */ + public function rotateAppPassword(): DataResponse { + 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 rotate apptoken'); + } + + $newToken = $this->random->generate(72, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS); + $this->tokenProvider->rotate($token, $appPassword, $newToken); + + return new DataResponse([ + 'apppassword' => $newToken, + ]); + } } |