janfish / auth
http auth
v1.0.3
2021-05-27 10:37 UTC
Requires
- php: >=7.1.0
- firebase/php-jwt: ^5.2
This package is not auto-updated.
Last update: 2025-03-05 05:35:32 UTC
README
认证组件
JWT
$auth = Janfish\Auth\Auth::getInstance([
'class' => MyIdentity::class,
'type' => 'jwt',
'setting' => [
'alg' => 'HS256',
'secret' => '123123123',
],
]);
$token = $auth->generateToken(1, ['name' => 'username']);
try{
if ($auth->authorize($token) === false) {
echo '失败';
die();
}
print_r([
$auth->getIdentity(),
$auth->getExtendedData(),
]);
}catch (\Janfish\Auth\Exception\ExpiredException $e){
echo '超时了' . PHP_EOL;
die();
}catch (\Exception $e){
echo '失败ma' . PHP_EOL;
die();
}
Basic
$auth = Janfish\Auth\Auth::getInstance([
'class' => MyIdentity::class,
'type' => 'basic'
]);
$token = $auth->generateToken('zeng444', 'password');
if ($auth->authorize($token) === false) {
echo '失败';
die();
}
print_r([
$auth->getIdentity(),
$auth->getExtendedData(),
]);
Reset
$auth = Janfish\Auth\Auth::getInstance([
'class' => MyIdentity::class,
'type' => 'basic'
]);
$auth->reset();