diff --git a/extend.php b/extend.php index 2d24d6b..32bee83 100644 --- a/extend.php +++ b/extend.php @@ -33,7 +33,12 @@ return [ ->post('/oauth-clients', 'oauth.clients.create', Api\Controller\CreateClientController::class) ->get('/oauth-clients/{client_id}', 'oauth.clients.show', Api\Controller\ShowClientController::class) ->patch('/oauth-clients/{id}', 'oauth.clients.update', Api\Controller\UpdateClientController::class) - ->delete('/oauth-clients/{id}', 'oauth.clients.delete', Api\Controller\DeleteClientController::class), + ->delete('/oauth-clients/{id}', 'oauth.clients.delete', Api\Controller\DeleteClientController::class) + + ->get('/oauth-scopes', 'oauth.clients.list', Api\Controller\ListClientController::class) + ->post('/oauth-scopes', 'oauth.clients.create', Api\Controller\CreateClientController::class) + ->patch('/oauth-scopes/{id}', 'oauth.clients.update', Api\Controller\UpdateClientController::class) + ->delete('/oauth-scopes/{id}', 'oauth.clients.delete', Api\Controller\DeleteClientController::class), (new Extend\Settings) ->serializeToForum('foskym-oauth-center.allow_implicit', 'foskym-oauth-center.allow_implicit', 'boolval') diff --git a/src/Api/Controller/CreateScopeController.php b/src/Api/Controller/CreateScopeController.php new file mode 100644 index 0000000..e679155 --- /dev/null +++ b/src/Api/Controller/CreateScopeController.php @@ -0,0 +1,25 @@ +assertAdmin(); + + $attributes = Arr::get($request->getParsedBody(), 'data.attributes'); + + return Scope::create([]); + } +} diff --git a/src/Api/Controller/DeleteScopeController.php b/src/Api/Controller/DeleteScopeController.php new file mode 100644 index 0000000..ec2e22e --- /dev/null +++ b/src/Api/Controller/DeleteScopeController.php @@ -0,0 +1,28 @@ +getQueryParams(), 'id'); + RequestUtil::getActor($request) + ->assertAdmin(); + + $client = Scope::find($id); + + $client->delete(); + + return $client; + } +} diff --git a/src/Api/Controller/ListScopeController.php b/src/Api/Controller/ListScopeController.php new file mode 100644 index 0000000..44344ef --- /dev/null +++ b/src/Api/Controller/ListScopeController.php @@ -0,0 +1,23 @@ +assertAdmin(); + + return Scope::all(); + } +} diff --git a/src/Api/Controller/UpdateScopeController.php b/src/Api/Controller/UpdateScopeController.php new file mode 100644 index 0000000..d226d38 --- /dev/null +++ b/src/Api/Controller/UpdateScopeController.php @@ -0,0 +1,37 @@ +assertAdmin(); + + $id = Arr::get($request->getQueryParams(), 'id'); + $client = Scope::find($id); + + $attributes = Arr::get($request->getParsedBody(), 'data.attributes', []); + + collect(['scope', 'resource_path', 'method', 'is_default', 'scope_name', 'scope_icon', 'scope_desc']) + ->each(function (string $attribute) use ($client, $attributes) { + if (($val = Arr::get($attributes, $attribute)) !== null) { + $client->$attribute = $val; + } + }); + + $client->save(); + + return $client; + } +} diff --git a/src/Api/Serializer/ScopeSerializer.php b/src/Api/Serializer/ScopeSerializer.php new file mode 100644 index 0000000..fabdbc7 --- /dev/null +++ b/src/Api/Serializer/ScopeSerializer.php @@ -0,0 +1,34 @@ + $model->id, + "scope" => $model->scope, + "resource_path" => $model->resource_path, + "method" => $model->method, + "is_default" => $model->is_default, + "scope_name" => $model->scope_name, + "scope_icon" => $model->scope_icon, + "scope_desc" => $model->scope_desc, + ]; + } +}