Compare commits
No commits in common. "master" and "1.0.1" have entirely different histories.
101
README.md
101
README.md
|
@ -15,7 +15,6 @@ PwsServer is a web application skeleton in silex2 managing web services through
|
||||||
### Install
|
### Install
|
||||||
|
|
||||||
The package can be installed using [ Composer ](https://getcomposer.org/).
|
The package can be installed using [ Composer ](https://getcomposer.org/).
|
||||||
|
|
||||||
```
|
```
|
||||||
composer require meta-tech/pws-server
|
composer require meta-tech/pws-server
|
||||||
```
|
```
|
||||||
|
@ -24,23 +23,20 @@ Or add the package to your `composer.json`.
|
||||||
|
|
||||||
```
|
```
|
||||||
"require": {
|
"require": {
|
||||||
"meta-tech/pws-server" : "^1.0"
|
"meta-tech/pws-server" : "~1.0"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Usage
|
## Usage
|
||||||
|
|
||||||
see [ MetaTech\Silex\Provider\ControllerServiceProvider ](https://github.com/meta-tech/silex-controller-service)
|
managing controllers & routing in application
|
||||||
to managing controllers & routing in application
|
cf [ MetaTech\Silex\Provider\ControllerServiceProvider ](https://github.com/meta-tech/silex-controller-service)
|
||||||
|
|
||||||
```php
|
```php
|
||||||
namespace MetaTech\PwsServer;
|
namespace MetaTech\PwsServer;
|
||||||
|
|
||||||
use MetaTech\Silex\Application as App;
|
use MetaTech\Silex\Application as App;
|
||||||
use MetaTech\Silex\Provider\ControllerServiceProvider as CtrlProvider;
|
use MetaTech\Silex\Provider\ControllerServiceProvider as CtrlProvider;
|
||||||
use MetaTech\Silex\Provider\UserProvider;
|
|
||||||
use MetaTech\Db\PdoWrapper;
|
|
||||||
use MetaTech\Db\Profile;
|
|
||||||
use MetaTech\PwsAuth\Authenticator;
|
use MetaTech\PwsAuth\Authenticator;
|
||||||
use MetaTech\PwsServer\Ctrl\Test;
|
use MetaTech\PwsServer\Ctrl\Test;
|
||||||
use MetaTech\PwsServer\Ctrl\WebService;
|
use MetaTech\PwsServer\Ctrl\WebService;
|
||||||
|
@ -48,20 +44,22 @@ use MetaTech\PwsServer\Ctrl\OtherWebService;
|
||||||
|
|
||||||
class Application extends App
|
class Application extends App
|
||||||
{
|
{
|
||||||
|
/*!
|
||||||
|
* @method setServices
|
||||||
|
* @protected
|
||||||
|
*/
|
||||||
protected function setServices()
|
protected function setServices()
|
||||||
{
|
{
|
||||||
$app = $this;
|
$app = $this;
|
||||||
$app['ws.authenticator'] = function ($app) {
|
$app['ws.authenticator'] = function ($app) {
|
||||||
return new Authenticator($app['config']['pwsauth']);
|
return new Authenticator($app['config']['pwsauth']);
|
||||||
};
|
};
|
||||||
$app['pdo'] = function ($app) {
|
|
||||||
return new PdoWrapper(new Profile($app['config']['db']['default']));
|
|
||||||
};
|
|
||||||
$app['user.provider'] = function ($app) {
|
|
||||||
return new UserProvider($app['pdo']);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @method routingDefinition
|
||||||
|
* @protected
|
||||||
|
*/
|
||||||
protected function routingDefinition()
|
protected function routingDefinition()
|
||||||
{
|
{
|
||||||
$this->register(new CtrlProvider(Test::class , [$this], '/'));
|
$this->register(new CtrlProvider(Test::class , [$this], '/'));
|
||||||
|
@ -74,9 +72,11 @@ class Application extends App
|
||||||
Controller example :
|
Controller example :
|
||||||
|
|
||||||
```php
|
```php
|
||||||
|
<?php
|
||||||
|
|
||||||
use Silex\ControllerCollection;
|
use Silex\ControllerCollection;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use MetaTech\PwsServer\Ws\Controller;
|
use MetaTech\Silex\Ws\Controller;
|
||||||
|
|
||||||
class WebService extends Controller
|
class WebService extends Controller
|
||||||
{
|
{
|
||||||
|
@ -99,70 +99,10 @@ class WebService extends Controller
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
`pwsAuth` Authentication mecanism is already provided by the `MetaTech\Silex\Ws\Controller` parent class
|
Authentication mecanism is already provided by the `MetaTech\Silex\Ws\Controller` parent class
|
||||||
& the `MetaTech\Silex\Ws\Authentication` handler (in [ meta-tech/silex-core](https://github.com/meta-tech/silex-core) package)
|
& the `MetaTech\Silex\Ws\Authentication` handler (in meta-tech/silex-core package)
|
||||||
|
|
||||||
Check `OtherWebService` to see another controller and deep routes inside rooting /ws entry point.
|
See OtherWebService to see another controller and deep routes inside rooting /ws entry point
|
||||||
The main différence consist in no calling the parent routing method, however the pwsauth authentication
|
|
||||||
still be active.
|
|
||||||
|
|
||||||
The project now implement the `checkUser` method via a `userProvider`
|
|
||||||
It use a `MetaTech\Silex\Ws\Authentication` and `MetaTech\Silex\Ws\Controller` subclasses :
|
|
||||||
|
|
||||||
```php
|
|
||||||
namespace MetaTech\PwsServer\Ws;
|
|
||||||
|
|
||||||
use Symfony\Component\HttpFoundation\Session\Session;
|
|
||||||
use Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface;
|
|
||||||
use MetaTech\PwsAuth\Authenticator;
|
|
||||||
use MetaTech\Silex\Ws\Authentication as BaseAuthentication;
|
|
||||||
use MetaTech\Silex\Provider\UserProvider;
|
|
||||||
|
|
||||||
class Authentication extends BaseAuthentication
|
|
||||||
{
|
|
||||||
protected $userProvider;
|
|
||||||
|
|
||||||
public function __construct(Session $session, Authenticator $authenticator, PasswordEncoderInterface $passEncoder = null, UserProvider $userProvider)
|
|
||||||
{
|
|
||||||
parent::__construct($session, $authenticator, $passEncoder);
|
|
||||||
$this->userProvider = $userProvider;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function checkUser($login, $password, $key, PasswordEncoderInterface $passEncoder = null)
|
|
||||||
{
|
|
||||||
$done = false;
|
|
||||||
try {
|
|
||||||
if (!is_null($passEncoder)) {
|
|
||||||
$user = $this->userProvider->loadUserByUsername($login);
|
|
||||||
$salt = $this->authenticator->getUserSalt($login);
|
|
||||||
$done = $user->key == $key && $passEncoder->encodePassword($password, $salt) == $user->getPassword();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(\Exception $e) {
|
|
||||||
//~ var_dump($e->getTraceAsString());
|
|
||||||
}
|
|
||||||
return $done;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
the controller :
|
|
||||||
|
|
||||||
```php
|
|
||||||
namespace MetaTech\PwsServer\Ws;
|
|
||||||
|
|
||||||
use Silex\Application;
|
|
||||||
use MetaTech\Silex\Ws\Controller as BaseController;
|
|
||||||
use MetaTech\PwsServer\Ws\Authentication;
|
|
||||||
|
|
||||||
class Controller extends BaseController
|
|
||||||
{
|
|
||||||
public function __construct(Application $app = null)
|
|
||||||
{
|
|
||||||
$this->session = $app['session'];
|
|
||||||
$this->handler = new Authentication($this->session, $app['ws.authenticator'], $app['security.encoder.pbkdf2'], $app['user.provider']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
### Test uris :
|
### Test uris :
|
||||||
|
@ -179,6 +119,11 @@ access through pws-client :
|
||||||
* servername/ws/isauth
|
* servername/ws/isauth
|
||||||
|
|
||||||
|
|
||||||
|
### @todo
|
||||||
|
|
||||||
|
subclassing `MetaTech\Silex\Ws\Authentication` to give checkUser db implementation example
|
||||||
|
|
||||||
|
|
||||||
### License
|
### License
|
||||||
|
|
||||||
The project is released under the MIT license, see the LICENSE file.
|
The project is released under the MIT license, see the LICENSE file.
|
||||||
|
|
|
@ -17,6 +17,6 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"meta-tech/silex-core" : "@dev"
|
"meta-tech/silex-core" : "~1.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user