2017 © Pedro Peláez
 

module roave-nonce-utility

A utility component for handling nonces

image

roave/roave-nonce-utility

A utility component for handling nonces

  • Sunday, February 18, 2018
  • by mac_nibblet
  • Repository
  • 4 Watchers
  • 4 Stars
  • 2,071 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 1 Open issues
  • 6 Versions
  • 2 % Grown

The README.md

Roave\NonceUtility

Build Status Scrutinizer Code Quality Build Status, (*1)

A simple module that helps with managing nonces, (*2)

Usage of this module assumes that you have already installed and configured the DoctrineModule available here http://github.com/doctrine/DoctrineModule, (*3)

Installation

Install the module by adding the module to your composer file, (*4)

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

Now you need to add an alias for the Roave\NonceUtility\ObjectManager to the object manager of your choice., (*6)

This is the standard configuration for most ORM users, (*7)

'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, (*8)

Again for most standard ORM users, (*9)

'doctrine' => [
  'entity_resolver' => array(
    'orm_default' => array(
      'resolvers' => [
        NonceOwnerInterface::class => AbstractUserEntity::class,
      ]
    ]
  ]
]

And the nonce owner entity class, (*10)

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

$service = $serviceLocator->get(NonceService::class);

The service interface is inlined here, (*12)

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);
}

The Versions