2017 © Pedro PelĂĄez
 

library pws-server

PwsServer is a web application skeleton in silex2 managing web services through PwsAuth protocol

image

meta-tech/pws-server

PwsServer is a web application skeleton in silex2 managing web services through PwsAuth protocol

  • Tuesday, March 21, 2017
  • by Meta-Tech
  • Repository
  • 1 Watchers
  • 0 Stars
  • 4 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

MetaTech PwsServer

PwsServer is a web application skeleton in silex2 managing web services through PwsAuth protocol, (*1)

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 ., (*2)

composer require meta-tech/pws-server

Or add the package to your composer.json., (*3)

"require": {
    "meta-tech/pws-server" : "^1.0"
}

Usage

see MetaTech\Silex\Provider\ControllerServiceProvider to managing controllers & routing in application, (*4)

namespace MetaTech\PwsServer;

use MetaTech\Silex\Application as App;
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\PwsServer\Ctrl\Test;
use MetaTech\PwsServer\Ctrl\WebService;
use MetaTech\PwsServer\Ctrl\OtherWebService;

class Application extends App
{
    protected function setServices()
    {
        $app = $this;
        $app['ws.authenticator'] = function ($app) {
            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']);
        };
    }

    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 :, (*5)

use Silex\ControllerCollection;
use Symfony\Component\HttpFoundation\Request;
use MetaTech\PwsServer\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;
    }
}

pwsAuth 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), (*6)

Check 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., (*7)

The project now implement the checkUser method via a userProvider
It use a MetaTech\Silex\Ws\Authentication and MetaTech\Silex\Ws\Controller subclasses :, (*8)

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 :, (*9)

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 :

access through web browser :, (*10)

  • servername/
  • servername/test

access through pws-client :, (*11)

  • servername/ws
  • servername/ws/deep
  • servername/ws/isauth

License

The project is released under the MIT license, see the LICENSE file., (*12)

The Versions

21/03 2017

dev-master

9999999-dev https://github.com/meta-tech/pws-server

PwsServer is a web application skeleton in silex2 managing web services through PwsAuth protocol

  Sources   Download

MIT

The Requires

 

silex server http webservice pwsauth

21/03 2017

1.0.2

1.0.2.0 https://github.com/meta-tech/pws-server

PwsServer is a web application skeleton in silex2 managing web services through PwsAuth protocol

  Sources   Download

MIT

The Requires

 

silex server http webservice pwsauth

15/03 2017

1.0.1

1.0.1.0 https://github.com/meta-tech/pws-server

PwsServer is a web application skeleton in silex2 managing web services through PwsAuth protocol

  Sources   Download

MIT

The Requires

 

silex server http webservice pwsauth

15/03 2017

1.0.0

1.0.0.0 https://github.com/meta-tech/pws-server

PwsServer is a web application skeleton in silex2 managing web services through PwsAuth protocol

  Sources   Download

MIT

The Requires

 

silex server http webservice pwsauth