initial commit
This commit is contained in:
commit
ea394b8925
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
vendor/
|
||||||
|
composer.lock
|
21
LICENSE
Normal file
21
LICENSE
Normal file
|
@ -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.
|
129
README.md
Normal file
129
README.md
Normal file
|
@ -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
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Silex\ControllerCollection;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use MetaTech\Silex\Ws\Controller;
|
||||||
|
|
||||||
|
class WebService extends Controller
|
||||||
|
{
|
||||||
|
public function index(Request $request)
|
||||||
|
{
|
||||||
|
$done = true;
|
||||||
|
$msg = 'this is index';
|
||||||
|
return $this->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.
|
39
composer.json
Normal file
39
composer.json
Normal file
|
@ -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"
|
||||||
|
}
|
10
config/main.yml
Normal file
10
config/main.yml
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
env :
|
||||||
|
name : local
|
||||||
|
prod : 0
|
||||||
|
debug : 1
|
||||||
|
url : pwsserver.docker
|
||||||
|
protocol : http
|
||||||
|
|
||||||
|
info :
|
||||||
|
app_name : pwsserver
|
||||||
|
version : 1.0.2
|
22
config/pwsauth.yml
Normal file
22
config/pwsauth.yml
Normal file
|
@ -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
|
||||||
|
|
50
src/MetaTech/PwsServer/Application.php
Normal file
50
src/MetaTech/PwsServer/Application.php
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* This file is part of the pws-server package.
|
||||||
|
*
|
||||||
|
* (c) meta-tech.academy
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @package MetaTech\PwsServer
|
||||||
|
* @class Application
|
||||||
|
* @extends Silex\Application
|
||||||
|
* @author a-Sansara
|
||||||
|
* @date 2017-03-12 21:46:43 CET
|
||||||
|
*/
|
||||||
|
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'));
|
||||||
|
}
|
||||||
|
}
|
52
src/MetaTech/PwsServer/Ctrl/OtherWebService.php
Normal file
52
src/MetaTech/PwsServer/Ctrl/OtherWebService.php
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* This file is part of the pws-server package.
|
||||||
|
*
|
||||||
|
* (c) meta-tech.academy
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
namespace MetaTech\PwsServer\Ctrl;
|
||||||
|
|
||||||
|
use Silex\Application;
|
||||||
|
use Silex\ControllerCollection;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use MetaTech\Silex\Ws\Controller;
|
||||||
|
/*!
|
||||||
|
* @package MetaTech\PwsServer\Ctrl
|
||||||
|
* @class OtherWebService
|
||||||
|
* @extends MetaTech\Silex\Ws\Controller
|
||||||
|
* @author a-Sansara
|
||||||
|
* @date 2017-03-12 15:39:30 CET
|
||||||
|
*/
|
||||||
|
class OtherWebService extends Controller
|
||||||
|
{
|
||||||
|
/*!
|
||||||
|
* @method index
|
||||||
|
* @public
|
||||||
|
* @return Symfony\Component\HttpFoundation\Response
|
||||||
|
*/
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$done = true;
|
||||||
|
$msg = 'this is deep index';
|
||||||
|
return $this->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;
|
||||||
|
}
|
||||||
|
}
|
50
src/MetaTech/PwsServer/Ctrl/Test.php
Normal file
50
src/MetaTech/PwsServer/Ctrl/Test.php
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* This file is part of the pws-server package.
|
||||||
|
*
|
||||||
|
* (c) meta-tech.academy
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
namespace MetaTech\PwsServer\Ctrl;
|
||||||
|
|
||||||
|
use Silex\Application;
|
||||||
|
use Silex\ControllerCollection;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use MetaTech\Silex\Ctrl\Base;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @package MetaTech\PwsServer\Ctrl
|
||||||
|
* @class Test
|
||||||
|
* @extends MetaTech\Silex\Ctrl\Base
|
||||||
|
* @author a-Sansara
|
||||||
|
* @date 2017-03-12 15:39:30 CET
|
||||||
|
*/
|
||||||
|
class Test extends Base
|
||||||
|
{
|
||||||
|
public function __construct(Application $app)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
return new Response('index');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test()
|
||||||
|
{
|
||||||
|
return new Response('test');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function routing(ControllerCollection $collection): ControllerCollection
|
||||||
|
{
|
||||||
|
$_ = $this->ns();
|
||||||
|
|
||||||
|
$collection->match('/' , "$_:index");
|
||||||
|
$collection->match('/test', "$_:test");
|
||||||
|
|
||||||
|
return $collection;
|
||||||
|
}
|
||||||
|
}
|
53
src/MetaTech/PwsServer/Ctrl/WebService.php
Normal file
53
src/MetaTech/PwsServer/Ctrl/WebService.php
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* This file is part of the pws-server package.
|
||||||
|
*
|
||||||
|
* (c) meta-tech.academy
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
namespace MetaTech\PwsServer\Ctrl;
|
||||||
|
|
||||||
|
use Silex\Application;
|
||||||
|
use Silex\ControllerCollection;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use MetaTech\Silex\Ws\Controller;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @package MetaTech\PwsServer\Ctrl
|
||||||
|
* @class WebService
|
||||||
|
* @extends MetaTech\Silex\Ws\Controller
|
||||||
|
* @author a-Sansara
|
||||||
|
* @date 2017-03-12 15:39:30 CET
|
||||||
|
*/
|
||||||
|
class WebService extends Controller
|
||||||
|
{
|
||||||
|
/*!
|
||||||
|
* @method index
|
||||||
|
* @public
|
||||||
|
* @return Symfony\Component\HttpFoundation\Response
|
||||||
|
*/
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$done = true;
|
||||||
|
$msg = 'this is index';
|
||||||
|
return $this->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;
|
||||||
|
}
|
||||||
|
}
|
4
web/index.php
Normal file
4
web/index.php
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
<?php
|
||||||
|
require_once(dirname(__dir__) . '/vendor/autoload.php');
|
||||||
|
|
||||||
|
(new MetaTech\PwsServer\Application(['path' => dirname(__dir__)]))->run();
|
Loading…
Reference in New Issue
Block a user