cac / api-token
API Token creator and validator
dev-master
2013-04-28 20:36 UTC
Requires
- php: >=5.3.3
- ext-mcrypt: *
Requires (Dev)
- phpunit/phpunit: >=3.7
This package is not auto-updated.
Last update: 2024-11-19 05:57:10 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