2017 © Pedro Peláez
 

library silex-wsse

WSSE implementation based on Silex examples in documentation.

image

alcalyn/silex-wsse

WSSE implementation based on Silex examples in documentation.

  • Tuesday, September 26, 2017
  • by alcalyn
  • Repository
  • 0 Watchers
  • 2 Stars
  • 100 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

Silex WSSE

Latest Stable Version License, (*1)

Provides a Silex provider in order to implement a WSSE authentication., (*2)

Installation

Via Composer, (*3)

``` js { "require": { "alcalyn/silex-wsse": "~1.0.0" } }, (*4)



## Usage ``` php // Register Silex security $app->register(new Silex\Provider\SecurityServiceProvider(), array( 'security.firewalls' => array( 'api' => array( 'pattern' => '^/api', 'wsse' => true, 'stateless' => true, 'users' => $myUserProvider, ), ), )); // SilexWsse needs a token validator service with a path where to store Wsse tokens $app['security.wsse.token_validator'] = function () { $wsseCacheDir = 'var/cache/wsse-tokens'; return new PasswordDigestValidator($wsseCacheDir); }; // Register Wsse provider $app->register(new WsseServiceProvider('api'));

Then you can retrieve your authenticated user in controller like that:, (*5)

``` php $app->get('api/auth', function () use ($app) { $authenticatedUser = $app['user'];, (*6)

return 'Hello '.$app->escape($authenticatedUser->getUsername());

});, (*7)


### Full example Using a plain password encoder, and an user `toto` with password `pass`: ``` php use Symfony\Component\Security\Core\User\InMemoryUserProvider; use Symfony\Component\Security\Core\Encoder\PlaintextPasswordEncoder; use Alcalyn\Wsse\Security\Authentication\Provider\PasswordDigestValidator; use Alcalyn\SilexWsse\Provider\WsseServiceProvider; $app = new Silex\Application(); $myUserProvider = function () { return new InMemoryUserProvider(array( 'toto' => ['password' => 'pass'], )); }; $app['security.default_encoder'] = function () { return new PlaintextPasswordEncoder(); }; // Register Silex security $app->register(new Silex\Provider\SecurityServiceProvider(), array( 'security.firewalls' => array( 'api' => array( 'pattern' => '^/api', 'wsse' => true, 'stateless' => true, 'users' => $myUserProvider, ), ), )); // SilexWsse needs a token validator service with a path where to store Wsse tokens $app['security.wsse.token_validator'] = function () { $wsseCacheDir = 'var/cache/wsse-tokens'; return new PasswordDigestValidator($wsseCacheDir); }; // Register Wsse provider $app->register(new WsseServiceProvider('api')); $app->get('api/auth', function () use ($app) { $authenticatedUser = $app['user']; return 'Hello '.$app->escape($authenticatedUser->getUsername()); }); $app->run();

Then making the following http request with the X-WSSE header (generated here):, (*8)

GET http://localhost/my-app/index.php/api/auth
X-WSSE: UsernameToken Username="toto", PasswordDigest="ieIS4sijyAW2ZrnvhvDOqBH+aSQ=", Nonce="NDlhNWE2M2YxNWQ2ZDk1NA==", Created="2016-07-31T12:46:16Z"

Returns the response:, (*9)

200 OK
Date:  Sun, 31 Jul 2016 12:46:25 GMT

Hello toto

Debugging

While implementing Wsse authentication, you should experience some authentication fail with your Wsse token (date expired, already used nonce...)., (*10)

To display the fail reason, you can display symfony authentication exception like that:, (*11)

``` php use Symfony\Component\Security\Core\Event\AuthenticationFailureEvent;, (*12)

$app->on('security.authentication.failure', function(AuthenticationFailureEvent $event) { echo $event->getAuthenticationException()->getMessage(); }); ```, (*13)

See Symfony documentation about authentication events., (*14)

License

This project is under MIT License., (*15)

The Versions

26/09 2017

dev-master

9999999-dev https://github.com/alcalyn/silex-wsse

WSSE implementation based on Silex examples in documentation.

  Sources   Download

MIT

The Requires

 

user silex symfony wsse

26/09 2017

1.1.0

1.1.0.0 https://github.com/alcalyn/silex-wsse

WSSE implementation based on Silex examples in documentation.

  Sources   Download

MIT

The Requires

 

user silex symfony wsse

26/09 2017

dev-dev

dev-dev https://github.com/alcalyn/silex-wsse

WSSE implementation based on Silex examples in documentation.

  Sources   Download

MIT

The Requires

 

user silex symfony wsse

31/07 2016

1.0.3

1.0.3.0 https://github.com/alcalyn/silex-wsse

WSSE implementation based on Silex examples in documentation.

  Sources   Download

MIT

The Requires

 

user silex symfony wsse

01/10 2015

v1.0.2

1.0.2.0 https://github.com/alcalyn/silex-wsse

WSSE implementation based on Silex examples in documentation.

  Sources   Download

MIT

The Requires

 

user silex symfony wsse

24/09 2015

1.0.1

1.0.1.0 https://github.com/alcalyn/silex-wsse

WSSE implementation based on Silex examples in documentation.

  Sources   Download

MIT

The Requires

 

user silex symfony wsse

22/09 2015

1.0.0

1.0.0.0 https://github.com/alcalyn/silex-wsse

WSSE implementation based on Silex examples in documentation.

  Sources   Download

MIT

The Requires

 

user silex symfony wsse