diff --git a/appinfo/routes.php b/appinfo/routes.php index 16a08d94..d58f751d 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -31,6 +31,7 @@ ['name' => 'login#backChannelLogout', 'url' => '/backchannel-logout/{providerIdentifier}', 'verb' => 'POST'], ['name' => 'api#createUser', 'url' => '/user', 'verb' => 'POST'], + ['name' => 'api#deleteUser', 'url' => '/user/{userId}', 'verb' => 'DELETE'], ['name' => 'id4me#showLogin', 'url' => '/id4me', 'verb' => 'GET'], ['name' => 'id4me#login', 'url' => '/id4me', 'verb' => 'POST'], diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php index 5b74d6d5..efade9c8 100644 --- a/lib/Controller/ApiController.php +++ b/lib/Controller/ApiController.php @@ -28,6 +28,7 @@ use OCA\UserOIDC\AppInfo\Application; use OCA\UserOIDC\Db\UserMapper; use OCP\AppFramework\Controller; +use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; use OCP\Files\IRootFolder; use OCP\Files\NotPermittedException; @@ -97,4 +98,20 @@ public function createUser(int $providerId, string $userId, ?string $displayName return new DataResponse(['user_id' => $user->getUID()]); } + + /** + * @param string $userId + * @return DataResponse + */ + public function deleteUser(string $userId): DataResponse { + $status = Http::STATUS_NOT_FOUND; + $user = $this->userManager->get($userId); + + if (!is_null($user) && $user->getBackendClassName() === 'user_oidc') { + $user->delete(); + $status = Http::STATUS_OK; + } + + return new DataResponse(['user_id' => $userId], $status); + } }