2017 © Pedro Peláez
 

library tokenista

Simple signed and expiring token generator and validator - for password reset, CSRF, authentication, whatever

image

ingenerator/tokenista

Simple signed and expiring token generator and validator - for password reset, CSRF, authentication, whatever

  • Wednesday, May 30, 2018
  • by acoulton
  • Repository
  • 3 Watchers
  • 10 Stars
  • 9,452 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 8 Versions
  • 10 % Grown

The README.md

Tokenista - generate and validate signed tokens

  • Master Build Status

Tokenista is a lightweight library for generating and validating signed tokens that can be used for password reset links, authentication, CSRF or anything else you may require. It aims to be secure (though you should always review all security related code) and to have minimum external dependencies., (*1)

Installation

Add tokenista to your composer.json and run composer update to install it., (*2)

{
  "require": { "ingenerator/tokenista": "^1.4" }
}

Basic Usage

$secret = 'some-constant-secret-value';
$tokenista = new \Ingenerator\Tokenista($secret, array('lifetime' => 3600));

// Generate with default lifetime from constructor options
$token = $tokenista->generate();

// Overall check if token is valid
if ($tokenista->isValid($token)) {
  // Do whatever
}

// Or for more control use:
$tokenista->isExpired($token);
$tokenista->isTampered($token);

Tokenista generates tokens as a single string of the form {random}-{expirytime}-{signature}, base64 encoded so suitable for inclusion in most places., (*3)

Verifying additional values

You may want to use Tokenista's signing mechanism to verify that some additional data has not been tampered with. For example, you could use this to include email address or other confirmation information in a URL rather than having to store a record of the mapping between token and user server side., (*4)

$token = $tokenista->generate(3600, ['user_id' => 9123]);

// Then, later:
if ($tokenista->isValid($_GET['token'], ['user_id' => $_GET['user_id']]) {
  // You can now trust user_id, even if it came through the URL, because it matches the value you originally signed
  // for this token.
}

Rotating secrets

It's good practice to occasionally rotate secrets - but without invalidating signatures that haven't yet expired. This is easily done - add an old_secrets config option with any previous secrets that should still be valid. Tokenista will start using the new secret to produce new tokens while still accepting tokens signed with an older value., (*5)

Once your maximum token expiry liftime has passed you can then remove the old secret from your list and Tokenista will stop accepting it., (*6)

Testing and developing

tokenista has a full suite of PHPUnit unit tests - run them with ./vendor/bin/phpunit. Contributions will only be accepted if they are accompanied by well structured unit tests. Installing with composer should get you everything you need to work on the project., (*7)

License

tokenista is copyright 2014 inGenerator Ltd and released under the BSD license., (*8)

The Versions

30/05 2018

dev-master

9999999-dev https://github.com/ingenerator/tokenista

Simple signed and expiring token generator and validator - for password reset, CSRF, authentication, whatever

  Sources   Download

BSD BSD-3-Clause

The Requires

  • ext-openssl *
  • lib-openssl *
  • php >=5.5

 

The Development Requires

auth token csrf

26/02 2018

v1.1.0

1.1.0.0 https://github.com/ingenerator/tokenista

Simple signed and expiring token generator and validator - for password reset, CSRF, authentication, whatever

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.5
  • ext-openssl *
  • lib-openssl *

 

The Development Requires

auth token csrf

26/02 2018

dev-0.1/support-secret-rotation

dev-0.1/support-secret-rotation https://github.com/ingenerator/tokenista

Simple signed and expiring token generator and validator - for password reset, CSRF, authentication, whatever

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.5
  • ext-openssl *
  • lib-openssl *

 

The Development Requires

auth token csrf

26/02 2018

dev-0.1/reformat-code

dev-0.1/reformat-code https://github.com/ingenerator/tokenista

Simple signed and expiring token generator and validator - for password reset, CSRF, authentication, whatever

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.5
  • ext-openssl *
  • lib-openssl *

 

The Development Requires

auth token csrf

02/03 2017

v1.0.2

1.0.2.0 https://github.com/ingenerator/tokenista

Simple signed and expiring token generator and validator - for password reset, CSRF, authentication, whatever

  Sources   Download

BSD

The Requires

  • php >=5.3.3
  • ext-openssl *
  • lib-openssl *

 

The Development Requires

auth token csrf

11/05 2015

v1.0.1

1.0.1.0 https://github.com/ingenerator/tokenista

Simple signed and expiring token generator and validator - for password reset, CSRF, authentication, whatever

  Sources   Download

BSD

The Requires

  • php >=5.3.3
  • ext-openssl *
  • lib-openssl *

 

The Development Requires

auth token csrf

11/05 2015

v1.0.0

1.0.0.0 https://github.com/ingenerator/tokenista

Simple signed and expiring token generator and validator - for password reset, CSRF, authentication, whatever

  Sources   Download

BSD

The Requires

  • php >=5.3.3
  • ext-openssl *
  • lib-openssl *

 

The Development Requires

auth token csrf

12/03 2014

v0.1.0

0.1.0.0 https://github.com/ingenerator/tokenista

Simple signed and expiring token generator and validator - for password reset, CSRF, authentication, whatever

  Sources   Download

BSD

The Requires

  • php >=5.3.3
  • ext-openssl *
  • lib-openssl *

 

The Development Requires

auth token csrf