diff --git a/app/Http/Controllers/API/oAuthController.php b/app/Http/Controllers/API/oAuthController.php index e877525..8c24adb 100644 --- a/app/Http/Controllers/API/oAuthController.php +++ b/app/Http/Controllers/API/oAuthController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers\API; use App\Entity\Token; use App\Exceptions\HTTPException; +use App\Exceptions\NoPermissionException; use App\Exceptions\NotLoggedInException; use App\Exceptions\ResourceNotFound; use App\Http\Resources\API\AppAccessDetails; @@ -105,7 +106,7 @@ class oAuthController extends BaseController } public function listAccess(Response $response) { if(!Auth::check()) { - abort(401); + throw new NotLoggedInException(); } $access = AppAccess::query()->where("user_id", "=", Auth::user()->id)->get(); @@ -118,4 +119,26 @@ class oAuthController extends BaseController return $response->withData(AppAccessDetails::collection(collect($visibleAccess))); } + public function removeAccess($id, Response $response) { + if(!Auth::check()) { + throw new NotLoggedInException(); + } + + $access = AppAccess::query()->where("id", "=", $id)->firstOrFail(); + if($access->user_id != Auth::user()->id) { + throw new NoPermissionException(); + } + + if($access->getApp()->user_cant_remove_app) { + throw new NoPermissionException(); + } + + RefreshToken::query()->where("access_id", "=", $access->id)->delete(); + \App\Models\AccessToken::query()->where("access_id", "=", $access->id)->delete(); + AppCode::query()->where("access_id", "=", $access->id)->delete(); + $access->delete(); + + + return $response; + } } diff --git a/app/Http/Resources/API/AppAccessDetails.php b/app/Http/Resources/API/AppAccessDetails.php index 0dc0b8c..97c6439 100644 --- a/app/Http/Resources/API/AppAccessDetails.php +++ b/app/Http/Resources/API/AppAccessDetails.php @@ -16,6 +16,7 @@ class AppAccessDetails extends JsonResource { $app = $this->getApp(); return [ + 'id' => $this->id, 'app' => new App($app), 'status' => $this->status, 'created' => $this->created_at->format('Y-m-d H:i:s e'), diff --git a/routes/web.php b/routes/web.php index b67fc7f..fdd4c1d 100644 --- a/routes/web.php +++ b/routes/web.php @@ -62,6 +62,7 @@ $router->group(['prefix' => 'api'], function () use ($router) { }); $router->group(["prefix" => "access"], function () use ($router) { $router->get("", ["uses" => "API\oAuthController@listAccess"]); + $router->delete("/{id}", ["uses" => "API\oAuthController@removeAccess"]); }); $router->group(['prefix' => 'account'], function () use ($router) { $router->get("/", ['uses' => 'API\AccountController@getUsers']);