roave / roave-nonce-utility
A utility component for handling nonces
Installs: 4 607
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 6
Forks: 2
Open Issues: 1
Type:module
Requires
- php: >=7.2.0
- doctrine/doctrine-module: ^0.9 || ^1.1 || ^2.0
- zendframework/zend-http: ^2.5 || ^3.0
- zendframework/zend-math: ^2.5 || ^3.0
- zendframework/zend-servicemanager: ^2.5 || ^3.0
- zendframework/zend-stdlib: ^2.5 || ^3.0
Requires (Dev)
- phpunit/phpunit: ~4.0
- satooshi/php-coveralls: ~0.6
- squizlabs/php_codesniffer: ~1.5.2
README
A simple module that helps with managing nonces
Usage of this module assumes that you have already installed and configured the DoctrineModule available here http://github.com/doctrine/DoctrineModule
Installation
Install the module by adding the module to your composer file
php composer.phar require roave/roave-nonce-utility:~2.0.0
After this you must enable the module by adding Roave\NonceUtility
to your
application.config.php
usually found in the config
directory in the application
root.
Now you need to add an alias for the Roave\NonceUtility\ObjectManager
to
the object manager of your choice.
This is the standard configuration for most ORM
users
'service_manager' => [ 'aliases' => [ 'Roave\NonceUtility\ObjectManager' => 'Doctrine\ORM\EntityManager' ] ]
The last step is to add an entity resolver for our interface to the doctrine configuration and have that class implement the NonceOwnerInterface
Again for most standard ORM
users
'doctrine' => [ 'entity_resolver' => array( 'orm_default' => array( 'resolvers' => [ NonceOwnerInterface::class => AbstractUserEntity::class, ] ] ] ]
And the nonce owner entity class
abstract class AbstractUser implements NonceOwnerInterface { public function getId() { // Return your unique identifier..... } }
Usage
To use the module you simply need aquire the nonce service from the service locator
$service = $serviceLocator->get(NonceService::class);
The service interface is inlined here
interface NonceServiceInterface { /** * Create a new nonce * * @param NonceOwnerInterface $owner * @param string $namespace * @param DateInterval|null $expiresIn * @param integer $length * * @return NonceEntity */ public function createNonce(NonceOwnerInterface $owner, $namespace = 'default', DateInterval $expiresIn = null, $length = 10); /** * Consume a nonce * * @param NonceOwnerInterface $owner * @param string $nonce * @param string $namespace * @param RequestInterface $request * * @throws Exception\NonceNotFoundException * @throws Exception\NonceAlreadyConsumedException * @throws Exception\NonceHasExpiredException * * @return void */ public function consume(NonceOwnerInterface $owner, $nonce, $namespace = 'default', RequestInterface $request = null); }