cac/api-token

API令牌创建和验证器

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

This package is not auto-updated.

Last update: 2024-09-24 05:10:48 UTC


README

创建和验证API令牌

在此示例中,我们基于用户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);

从令牌中获取用户ID

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

当提供无效令牌时,validateToken 方法返回 FALSE