zacharyrankin / hmac-auth
PHP的简单令牌认证
v0.2
2015-06-13 20:18 UTC
Requires (Dev)
- phpunit/phpunit: ~4.7
This package is not auto-updated.
Last update: 2024-09-28 18:10:31 UTC
README
PHP的简单令牌认证
用法
通过Composer要求
composer require zacharyrankin/hmac-auth
客户端
use zacharyrankin\hmac_auth\Authenticator; use zacharyrankin\hmac_auth\Client; $auth = new Authenticator; $token = $auth->createToken(new Client('some user', 'user secret')); header('X-Authorization-Token: ' . $token);
服务器
use zacharyrankin\hmac_auth\Authenticator; use zacharyrankin\hmac_auth\Client; $auth = new Authenticator $auth->authenticate( $_SERVER['HTTP_X_AUTHORIZATION_TOKEN'], function ($clientId) { return new Client($clientId, SomeModel::findSecret($clientId)); }, 300 // expiration in seconds );