From ea394b892571bd4081acd706f47564bca72d85e1 Mon Sep 17 00:00:00 2001 From: a-sansara Date: Wed, 15 Mar 2017 00:49:44 +0100 Subject: [PATCH] initial commit --- .gitignore | 2 + LICENSE | 21 +++ README.md | 129 ++++++++++++++++++ composer.json | 39 ++++++ config/main.yml | 10 ++ config/pwsauth.yml | 22 +++ src/MetaTech/PwsServer/Application.php | 50 +++++++ .../PwsServer/Ctrl/OtherWebService.php | 52 +++++++ src/MetaTech/PwsServer/Ctrl/Test.php | 50 +++++++ src/MetaTech/PwsServer/Ctrl/WebService.php | 53 +++++++ web/index.php | 4 + 11 files changed, 432 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 composer.json create mode 100644 config/main.yml create mode 100644 config/pwsauth.yml create mode 100644 src/MetaTech/PwsServer/Application.php create mode 100644 src/MetaTech/PwsServer/Ctrl/OtherWebService.php create mode 100644 src/MetaTech/PwsServer/Ctrl/Test.php create mode 100644 src/MetaTech/PwsServer/Ctrl/WebService.php create mode 100644 web/index.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d1502b0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +vendor/ +composer.lock diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d9b7477 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 meta-tech.academy + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..b70807d --- /dev/null +++ b/README.md @@ -0,0 +1,129 @@ + +# MetaTech PwsServer + +PwsServer is a web application skeleton in silex2 managing web services through PwsAuth protocol + + +### Requirements + +PHP 7.0 +meta-tech\silex 2 +meta-tech\silex-core +meta-tech\pws-client (to test ws) + + +### Install + +The package can be installed using [ Composer ](https://getcomposer.org/). (not yet) +``` +composer require meta-tech/pws-server +``` + +Or add the package to your `composer.json`. + +``` +"require": { + "meta-tech/pws-server" : "1.0" +} +``` + +## Usage + +managing controllers & routing in application +cf [ MetaTech\Silex\Provider\ControllerServiceProvider ](https://github.com/meta-tech/silex-controller-service) + +```php +namespace MetaTech\PwsServer; + +use MetaTech\Silex\Application as App; +use MetaTech\Silex\Provider\ControllerServiceProvider as CtrlProvider; +use MetaTech\PwsAuth\Authenticator; +use MetaTech\PwsServer\Ctrl\Test; +use MetaTech\PwsServer\Ctrl\WebService; +use MetaTech\PwsServer\Ctrl\OtherWebService; + +class Application extends App +{ + /*! + * @method setServices + * @protected + */ + protected function setServices() + { + $app = $this; + $app['ws.authenticator'] = function ($app) { + return new Authenticator($app['config']['pwsauth']); + }; + } + + /*! + * @method routingDefinition + * @protected + */ + protected function routingDefinition() + { + $this->register(new CtrlProvider(Test::class , [$this], '/')); + $this->register(new CtrlProvider(WebService::class , [$this], '/ws')); + $this->register(new CtrlProvider(OtherWebService::class, [$this], '/ws/deep')); + } +} +``` + +Controller example : + +```php +response($done, $msg); + } + + public function routing(ControllerCollection $collection) : ControllerCollection + { + $collection = parent::routing($collection); + $_ = $this->ns(); + + $collection->match('/', "$_:index"); + + return $collection; + } +} +``` + +Authentication mecanism is already provided by the `MetaTech\Silex\Ws\Controller` parent class +& the `MetaTech\Silex\Ws\Authentication` handler (in meta-tech/silex-core package) + +See OtherWebService to see another controller and deep routes inside rooting /ws entry point + + +### Test uris : + +access through web browser : + +* servername/ +* servername/test + +access through pws-client : + +* servername/ws +* servername/ws/deep +* servername/ws/isauth + + +### @todo + +subclassing `MetaTech\Silex\Ws\Authentication` to give checkUser db implementation example + + +### License + +The project is released under the MIT license, see the LICENSE file. diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..61dc611 --- /dev/null +++ b/composer.json @@ -0,0 +1,39 @@ +{ + "name" : "meta-tech/pws-server", + "type" : "library", + "homepage" : "https://github.com/meta-tech/pws-server", + "description" : "PwsServer is web application skeleton in silex2 managing web services through PwsAuth protocol", + "license" : "MIT", + "authors" : [ + { + "name" : "a-Sansara", + "homepage" : "https://github.com/a-sansara/" + } + ], + "keywords" : ["Server", "PwsAuth", "WebService", "Silex", "Http"], + "autoload" : { + "psr-4" : { + "" : "src/" + } + }, + "require": { + "meta-tech/silex-controller-service" : "@dev", + "meta-tech/pws-auth" : "@dev", + "meta-tech/silex-core" : "@dev" + }, + "repositories": [ + { + "type": "git", + "url": "https://github.com/meta-tech/silex-controller-service.git" + }, + { + "type": "git", + "url": "https://github.com/meta-tech/pws-auth.git" + }, + { + "type": "git", + "url": "https://github.com/meta-tech/silex-core.git" + } + ], + "minimum-stability": "dev" +} diff --git a/config/main.yml b/config/main.yml new file mode 100644 index 0000000..6e0186b --- /dev/null +++ b/config/main.yml @@ -0,0 +1,10 @@ +env : + name : local + prod : 0 + debug : 1 + url : pwsserver.docker + protocol : http + +info : + app_name : pwsserver + version : 1.0.2 diff --git a/config/pwsauth.yml b/config/pwsauth.yml new file mode 100644 index 0000000..e2b15d3 --- /dev/null +++ b/config/pwsauth.yml @@ -0,0 +1,22 @@ +type : PwsAuth2 + +header : + auth : Pws-Authorization + ident : Pws-Ident + +salt : + common : jK5#p9Mh5.Zv} + # used for generating user specific salt + user.index : 10 + user.length : 12 + +hash : + sep : / + algo : sha256 + # effective token length size. out of bound data is simply noise + length : 52 + # session index (or obfuscate length) + session.index : 58 + # ending noise data length) + noise.length : 12 + diff --git a/src/MetaTech/PwsServer/Application.php b/src/MetaTech/PwsServer/Application.php new file mode 100644 index 0000000..e4b6b5a --- /dev/null +++ b/src/MetaTech/PwsServer/Application.php @@ -0,0 +1,50 @@ +register(new CtrlProvider(Test::class , [$this], '/')); + $this->register(new CtrlProvider(WebService::class , [$this], '/ws')); + $this->register(new CtrlProvider(OtherWebService::class, [$this], '/ws/deep')); + } +} diff --git a/src/MetaTech/PwsServer/Ctrl/OtherWebService.php b/src/MetaTech/PwsServer/Ctrl/OtherWebService.php new file mode 100644 index 0000000..a5cd418 --- /dev/null +++ b/src/MetaTech/PwsServer/Ctrl/OtherWebService.php @@ -0,0 +1,52 @@ +response($done, $msg); + } + + /*! + * @method routing + * @public + * @param Silex\ControllerCollection $collection + * @return Silex\ControllerCollection + */ + public function routing(ControllerCollection $collection) : ControllerCollection + { + //~ $collection = parent::routing($collection); + $_ = $this->ns(); + + $collection->match('/', "$_:index"); + + return $collection; + } +} diff --git a/src/MetaTech/PwsServer/Ctrl/Test.php b/src/MetaTech/PwsServer/Ctrl/Test.php new file mode 100644 index 0000000..141060e --- /dev/null +++ b/src/MetaTech/PwsServer/Ctrl/Test.php @@ -0,0 +1,50 @@ +ns(); + + $collection->match('/' , "$_:index"); + $collection->match('/test', "$_:test"); + + return $collection; + } +} diff --git a/src/MetaTech/PwsServer/Ctrl/WebService.php b/src/MetaTech/PwsServer/Ctrl/WebService.php new file mode 100644 index 0000000..0c51fa6 --- /dev/null +++ b/src/MetaTech/PwsServer/Ctrl/WebService.php @@ -0,0 +1,53 @@ +response($done, $msg); + } + + /*! + * @method routing + * @public + * @param Silex\ControllerCollection $collection + * @return Silex\ControllerCollection + */ + public function routing(ControllerCollection $collection) : ControllerCollection + { + $collection = parent::routing($collection); + $_ = $this->ns(); + + $collection->match('/', "$_:index"); + + return $collection; + } +} diff --git a/web/index.php b/web/index.php new file mode 100644 index 0000000..2c1c775 --- /dev/null +++ b/web/index.php @@ -0,0 +1,4 @@ + dirname(__dir__)]))->run();