cac/api-token

API Token creator and validator

dev-master 2013-04-28 20:36 UTC

This package is not auto-updated.

Last update: 2024-12-17 06:23:15 UTC


README

Create and validate API tokens

In this example we create a new token based on the user ID

# ... user is logged in with user id 123
use CAC\Component\Token\Encrypt\McryptToken;
use CAC\Component\Token\TokenGenerator;

$tokenEncrypter = new McryptToken();
$tokenGenerator = new TokenGenerator($tokenEncrypter, 's3cr3tKeY$$');

$token = $tokenGenerator->createToken(123);

Get the user ID back from the token

$userId = $tokenGenerator->validateToken($token);
# $userId = 123

When an invalid token is given the validateToken method returns FALSE