Skip to content

Commit

Permalink
feat(ApiController): add endpoint to de-provision user
Browse files Browse the repository at this point in the history
Signed-off-by: Edward Ly <contact@edward.ly>
  • Loading branch information
edward-ly committed Oct 10, 2024
1 parent 94a818b commit e43c364
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
17 changes: 17 additions & 0 deletions lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

0 comments on commit e43c364

Please sign in to comment.