mirror of
https://gitee.com/ctexthuang/hyperf_rbac_framework_server_ctexthuang.git
synced 2025-12-25 15:57:50 +08:00
58 lines
1.2 KiB
PHP
58 lines
1.2 KiB
PHP
<?php
|
|
/**
|
|
* This service file is part of item.
|
|
*
|
|
* @author ctexthuang
|
|
* @contact ctexthuang@qq.com
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Service;
|
|
|
|
use App\Common\Interface\CheckTokenInterface;
|
|
use App\Common\Interface\JwtInterface;
|
|
use App\Exception\ErrException;
|
|
use App\Lib\Jwt\JwtFactory;
|
|
use Hyperf\Di\Annotation\Inject;
|
|
use Lcobucci\JWT\Token\RegisteredClaims;
|
|
use Lcobucci\JWT\UnencryptedToken;
|
|
use function Hyperf\Support\value;
|
|
|
|
final class BaseTokenService implements CheckTokenInterface
|
|
{
|
|
private string $jwt = 'admin';
|
|
|
|
/**
|
|
* @var JwtFactory
|
|
*/
|
|
#[Inject]
|
|
protected JwtFactory $jwtFactory;
|
|
|
|
/**
|
|
* @return JwtInterface
|
|
*/
|
|
public function getJwt(): JwtInterface
|
|
{
|
|
return $this->jwtFactory->get($this->jwt);
|
|
}
|
|
|
|
/**
|
|
* @param UnencryptedToken $token
|
|
* @return void
|
|
*/
|
|
public function checkJwt(UnencryptedToken $token): void
|
|
{
|
|
$this->getJwt()->hasBlackList($token) && throw new ErrException('token已过期');
|
|
}
|
|
|
|
/**
|
|
* @param string $jwt
|
|
* @return $this
|
|
*/
|
|
public function setJwt(string $jwt): self
|
|
{
|
|
$this->jwt = $jwt;
|
|
return $this;
|
|
}
|
|
} |